From 46bcba57aff601718a1791518bbb424ed5a4e39c Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Mon, 24 Aug 2020 22:24:02 +0200 Subject: [PATCH] Support Picture-in-Picture in ExoPlayer --- app/src/main/AndroidManifest.xml | 1 + .../jellyfin/mobile/player/PlayerActivity.kt | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9e17ac89..0297135c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,6 +36,7 @@ android:name=".player.PlayerActivity" android:launchMode="singleTop" android:screenOrientation="sensorLandscape" + android:supportsPictureInPicture="true" android:theme="@style/AppTheme.Player" /> = Build.VERSION_CODES.O && isInPictureInPictureMode) { + playerView.useController = false + } + // Handle current orientation and update fullscreen state restoreFullscreenState() setupFullscreenSwitcher() @@ -248,6 +251,16 @@ class PlayerActivity : AppCompatActivity() { return viewModel.mediaSourceManager.selectSubtitle(index) } + override fun onUserLeaveHint() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && viewModel.playerOrNull?.isPlaying == true) { + enterPictureInPictureMode(PictureInPictureParams.Builder().build()) + } + } + + override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) { + playerView.useController = !isInPictureInPictureMode + } + override fun onStop() { super.onStop() orientationListener.disable()