Skip to content

Commit

Permalink
feat(pip): automatically enter PictureInPicture with back button pres…
Browse files Browse the repository at this point in the history
…s/gesture

closes #13
  • Loading branch information
abdallahmehiz committed Sep 1, 2024
1 parent 798262c commit 52d2479
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ class PlayerActivity : AppCompatActivity() {
super.onUserLeaveHint()
}

@SuppressLint("NewApi")
override fun onBackPressed() {
if (isPipSupported && player.paused == false && playerPreferences.automaticallyEnterPip.get()) {
if (viewModel.sheetShown.value == Sheets.None && viewModel.panelShown.value == Panels.None) {
enterPictureInPictureMode()
}
} else {
super.onBackPressed()
}
}

override fun onStart() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setPictureInPictureParams(createPipParams())
Expand Down Expand Up @@ -382,7 +393,9 @@ class PlayerActivity : AppCompatActivity() {
}

override fun onConfigurationChanged(newConfig: Configuration) {
if (!isInPictureInPictureMode) viewModel.changeVideoAspect(playerPreferences.videoAspect.get())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (!isInPictureInPictureMode) viewModel.changeVideoAspect(playerPreferences.videoAspect.get())
}
super.onConfigurationChanged(newConfig)
}

Expand Down

0 comments on commit 52d2479

Please sign in to comment.