mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
add PiP support for offline player
This commit is contained in:
parent
cb4a61648f
commit
512844805a
@ -39,6 +39,8 @@
|
||||
|
||||
<activity
|
||||
android:name=".ui.activities.OfflinePlayerActivity"
|
||||
android:supportsPictureInPicture="true"
|
||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
||||
android:label="@string/player" />
|
||||
|
||||
<activity
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.github.libretube.ui.activities
|
||||
|
||||
import android.app.PictureInPictureParams
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.graphics.Color
|
||||
import android.media.session.PlaybackState
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
@ -10,10 +13,12 @@ import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.databinding.ActivityOfflinePlayerBinding
|
||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||
import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.util.DownloadHelper
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.source.MergingMediaSource
|
||||
@ -153,4 +158,26 @@ class OfflinePlayerActivity : BaseActivity() {
|
||||
player.release()
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user