return to main activity if pip was launched before

pull/24/head
Jannik 2 years ago
parent e5037cf9ac
commit 86e07ba2cf
Signed by: Seil0
GPG Key ID: E8459F3723C52C24

@ -32,6 +32,9 @@
android:label="@string/app_name"
android:theme="@style/PlayerTheme"
android:supportsPictureInPicture="true"
android:launchMode="singleTask"
android:excludeFromRecents="true"
android:taskAffinity=".player.PlayerActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|layoutDirection">
</activity>
</application>

@ -3,7 +3,10 @@ package org.mosad.teapod.player
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.annotation.SuppressLint
import android.app.ActivityManager
import android.app.PictureInPictureParams
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.os.Build
@ -35,6 +38,7 @@ import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.concurrent.scheduleAtFixedRate
class PlayerActivity : AppCompatActivity() {
private val model: PlayerViewModel by viewModels()
@ -43,6 +47,7 @@ class PlayerActivity : AppCompatActivity() {
private lateinit var gestureDetector: GestureDetectorCompat
private lateinit var timerUpdates: TimerTask
private var wasInPIP = false
private var playWhenReady = true
private var currentWindow = 0
private var playbackPosition: Long = 0
@ -117,6 +122,10 @@ class PlayerActivity : AppCompatActivity() {
video_view?.onPause()
releasePlayer()
}
if (wasInPIP) {
navToLauncherTask()
}
}
override fun onSaveInstanceState(outState: Bundle) {
@ -146,10 +155,15 @@ class PlayerActivity : AppCompatActivity() {
.build()
enterPictureInPictureMode(params)
}
wasInPIP = isInPiPMode()
}
}
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration?) {
override fun onPictureInPictureModeChanged(
isInPictureInPictureMode: Boolean,
newConfig: Configuration?
) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
// Hide the full-screen UI (controls, etc.) while in picture-in-picture mode.
@ -434,6 +448,21 @@ class PlayerActivity : AppCompatActivity() {
}
}
/**
* Bring up launcher task to front
*/
private fun navToLauncherTask() {
val activityManager = (this.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager)
activityManager.appTasks.forEach { task ->
val baseIntent = task.taskInfo.baseIntent
val categories = baseIntent.categories
if (categories != null && categories.contains(Intent.CATEGORY_LAUNCHER)) {
task.moveToFront()
return
}
}
}
/**
* pause playback and hide controls
*/

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close