Skip to content

Commit

Permalink
keep the video playing after the screen timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ratanparai committed Apr 27, 2019
1 parent 4b8c888 commit 5ec9e13
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.ratanparai.moviedog.player

import android.app.Activity
import android.content.Context
import android.support.v4.media.session.MediaControllerCompat
import android.util.Log
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import androidx.leanback.media.PlaybackTransportControlGlue
import androidx.leanback.media.PlayerAdapter
import androidx.leanback.widget.Action
Expand Down Expand Up @@ -60,6 +62,15 @@ class VideoPlayerGlue<T : PlayerAdapter>(context: Context, adapter: T, mediaCont

}

override fun onPlayStateChanged() {
super.onPlayStateChanged()
if(isPlaying) {
(context as Activity).window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
(context as Activity).window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}

override fun onUpdateProgress() {
super.onUpdateProgress()
movieService.updateMovieProgress(movieId, currentPosition)
Expand Down

0 comments on commit 5ec9e13

Please # to comment.