Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce onPictureInPictureModeChanged to FlutterPlayerView (PiP #2) #86

Merged
merged 10 commits into from
Dec 22, 2023
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.bitmovin.player.flutter

import android.content.ComponentCallbacks
import android.content.Context
import android.content.res.Configuration
import android.view.View
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -38,7 +40,20 @@ class FlutterPlayerView(
)

private val activity = context.requireActivity()
private val playerView: PlayerView = PlayerView(context, player = null)
private val playerView = PlayerView(context, player = null)
private var isInPictureInPictureMode = activity.isInPictureInPictureMode
private val configurationChangedCallback =
object : ComponentCallbacks {
override fun onConfigurationChanged(newConfig: Configuration) {
val newInPictureInPictureMode = activity.isInPictureInPictureMode
if (isInPictureInPictureMode != newInPictureInPictureMode) {
isInPictureInPictureMode = newInPictureInPictureMode
onPictureInPictureModeChanged(newInPictureInPictureMode, newConfig)
}
}

override fun onLowMemory() = Unit
}

private val activityLifecycle =
activity.let { it as? FlutterActivity ?: it as? FlutterFragmentActivity }
Expand Down Expand Up @@ -77,6 +92,14 @@ class FlutterPlayerView(
}

activityLifecycle.addObserver(activityLifecycleObserver)
activity.registerComponentCallbacks(configurationChangedCallback)
}

private fun onPictureInPictureModeChanged(
isInPictureInPictureMode: Boolean,
newConfig: Configuration,
) {
// TODO: Handle picture in picture mode changed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this TODO will be part of a future PR, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 🙂

}

override fun onMethodCall(
Expand All @@ -97,6 +120,7 @@ class FlutterPlayerView(
methodChannel.setMethodCallHandler(null)
eventChannel.setStreamHandler(null)
activityLifecycle.removeObserver(activityLifecycleObserver)
activity.unregisterComponentCallbacks(configurationChangedCallback)
}

override fun onListen(
Expand Down