add PiP support for offline player

This commit is contained in:
Bnyro 2022-10-07 19:09:44 +02:00
parent cb4a61648f
commit 512844805a
2 changed files with 29 additions and 0 deletions

View File

@ -39,6 +39,8 @@
<activity <activity
android:name=".ui.activities.OfflinePlayerActivity" android:name=".ui.activities.OfflinePlayerActivity"
android:supportsPictureInPicture="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:label="@string/player" /> android:label="@string/player" />
<activity <activity

View File

@ -1,8 +1,11 @@
package com.github.libretube.ui.activities package com.github.libretube.ui.activities
import android.app.PictureInPictureParams
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.graphics.Color import android.graphics.Color
import android.media.session.PlaybackState
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
@ -10,10 +13,12 @@ import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.WindowInsetsControllerCompat
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.databinding.ActivityOfflinePlayerBinding import com.github.libretube.databinding.ActivityOfflinePlayerBinding
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.util.DownloadHelper import com.github.libretube.util.DownloadHelper
import com.github.libretube.util.PreferenceHelper
import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.source.MergingMediaSource import com.google.android.exoplayer2.source.MergingMediaSource
@ -153,4 +158,26 @@ class OfflinePlayerActivity : BaseActivity() {
player.release() player.release()
super.onDestroy() super.onDestroy()
} }
override fun onUserLeaveHint() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
if (!PreferenceHelper.getBoolean(
PreferenceKeys.PICTURE_IN_PICTURE,
true
)
) {
return
}
if (player.playbackState == PlaybackState.STATE_PAUSED) return
enterPictureInPictureMode(
PictureInPictureParams.Builder()
.setActions(emptyList())
.build()
)
super.onUserLeaveHint()
}
} }