-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 7 commits
e67dbcd
98201b7
56eda99
90a7e46
1ec8988
6141522
8d9d802
986cbb1
97efb7a
b14d428
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ package com.bitmovin.player.flutter | |||||
import android.app.Activity | ||||||
import android.content.Context | ||||||
import android.content.ContextWrapper | ||||||
import android.content.res.Configuration | ||||||
import android.view.View | ||||||
import androidx.lifecycle.DefaultLifecycleObserver | ||||||
import androidx.lifecycle.LifecycleOwner | ||||||
|
@@ -37,7 +38,7 @@ class FlutterPlayerView( | |||||
messenger, | ||||||
) | ||||||
|
||||||
private val playerView: PlayerView = PlayerView(context, player = null) | ||||||
private val playerView = PlayerView(context, player = null) | ||||||
|
||||||
private val activity = | ||||||
context.getActivity() | ||||||
|
@@ -79,6 +80,13 @@ class FlutterPlayerView( | |||||
activityLifecycle.addObserver(activityLifecycleObserver) | ||||||
} | ||||||
|
||||||
private fun onPictureInPictureModeChanged( | ||||||
isInPictureInPictureMode: Boolean, | ||||||
newConfig: Configuration, | ||||||
) { | ||||||
// TODO: Handle picture in picture mode changed | ||||||
} | ||||||
|
||||||
override fun onMethodCall( | ||||||
call: MethodCall, | ||||||
result: MethodChannel.Result, | ||||||
|
@@ -111,6 +119,28 @@ class FlutterPlayerView( | |||||
sink = null | ||||||
} | ||||||
|
||||||
private fun PlayerView.setOnPictureInPictureModeChanged(callback: (Boolean, Configuration) -> Unit) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Where will this function be called from? I can't see any usage yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be called from the init block where we check out the playerView arguments. Right after the fullscreen handler initialization. |
||||||
var isInPictureInPictureMode = activity.isInPictureInPictureMode | ||||||
// Listening to PiP changes usually happens by overriding onPictureInPictureModeChanged in the Activity. | ||||||
// This is not really doable in a SDK context since the library consumer actually controls the activity. | ||||||
// To work around this limitation we listen to configuration changes and check if the PiP mode changed. | ||||||
// Since Flutter's PlatformView isn't actually an Android View, | ||||||
// we unfortunately cannot just override onConfigurationChanged function. | ||||||
// Instead, we add a blank View to the PlayerView and override its onConfigurationChanged function. | ||||||
// The alternative would be registering a ComponentCallbacks object to the activity, which unfortunately doesn't | ||||||
// work for some Android versions (tested on Android 10 with FlutterFragmentActivity). | ||||||
zigavehovec marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
addView( | ||||||
object : View(context) { | ||||||
override fun onConfigurationChanged(newConfig: Configuration) { | ||||||
if (isInPictureInPictureMode != activity.isInPictureInPictureMode) { | ||||||
isInPictureInPictureMode = activity.isInPictureInPictureMode | ||||||
callback(isInPictureInPictureMode, newConfig) | ||||||
} | ||||||
} | ||||||
}, | ||||||
) | ||||||
} | ||||||
|
||||||
private fun Context.getActivity(): Activity? = | ||||||
when (this) { | ||||||
is Activity -> this | ||||||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 🙂