Skip to content

Commit

Permalink
Merge pull request #639 from Infomaniak/fix-locked-phone-during-video
Browse files Browse the repository at this point in the history
prevent screen from locking when video is playing
  • Loading branch information
JorisBodin authored Mar 14, 2022
2 parents f9eef37 + d95bc34 commit bc6598f
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.core.net.toUri
import androidx.core.view.isGone
import androidx.core.view.isVisible
Expand Down Expand Up @@ -142,11 +143,14 @@ open class PreviewVideoFragment : PreviewFragment() {
exoPlayer?.addListener(object : Player.Listener {

override fun onIsPlayingChanged(isPlaying: Boolean) {
val flagKeepScreenOn = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
if (isPlaying) {
trackMediaPlayerEvent("play")
(parentFragment as? PreviewSliderFragment)?.toggleFullscreen()
activity?.window?.addFlags(flagKeepScreenOn)
} else {
trackMediaPlayerEvent("pause")
activity?.window?.clearFlags(flagKeepScreenOn)
}
}

Expand Down

0 comments on commit bc6598f

Please sign in to comment.