From 622f267934b09ab88d1741a8dacc57da16ed0394 Mon Sep 17 00:00:00 2001 From: Vehovec Date: Tue, 19 Dec 2023 17:16:17 +0100 Subject: [PATCH] chore: use picture in picture handler --- .../bitmovin/player/flutter/FlutterPlayerView.kt | 14 +++++++++++++- .../bitmovin/player/flutter/json/JsonObjects.kt | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/android/src/main/kotlin/com/bitmovin/player/flutter/FlutterPlayerView.kt b/android/src/main/kotlin/com/bitmovin/player/flutter/FlutterPlayerView.kt index 25ff63ca..e013c5fd 100644 --- a/android/src/main/kotlin/com/bitmovin/player/flutter/FlutterPlayerView.kt +++ b/android/src/main/kotlin/com/bitmovin/player/flutter/FlutterPlayerView.kt @@ -9,7 +9,9 @@ import android.view.View import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import com.bitmovin.player.PlayerView +import com.bitmovin.player.api.ui.PictureInPictureHandler import com.bitmovin.player.flutter.json.JPlayerViewCreateArgs +import com.bitmovin.player.flutter.ui.FlutterPictureInPictureHandler import io.flutter.plugin.common.BinaryMessenger import io.flutter.plugin.common.EventChannel import io.flutter.plugin.common.MethodCall @@ -58,6 +60,7 @@ class FlutterPlayerView( override fun onLowMemory() = Unit } + private var pictureInPicturehandler: PictureInPictureHandler? = null private val activityLifecycle = (activity as? LifecycleOwner) @@ -90,6 +93,10 @@ class FlutterPlayerView( ), ) } + if (playerViewCreateArgs.playerViewConfig?.pictureInPictureConfig?.isEnabled == true) { + pictureInPicturehandler = FlutterPictureInPictureHandler(activity, player) + playerView.setPictureInPictureHandler(pictureInPicturehandler) + } } activityLifecycle.addObserver(activityLifecycleObserver) @@ -100,7 +107,12 @@ class FlutterPlayerView( isInPictureInPictureMode: Boolean, newConfig: Configuration, ) { - // TODO: Handle picture in picture mode changed + playerView.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig) + if (isInPictureInPictureMode) { + playerView.enterPictureInPicture() + } else { + playerView.exitPictureInPicture() + } } override fun onMethodCall( diff --git a/android/src/main/kotlin/com/bitmovin/player/flutter/json/JsonObjects.kt b/android/src/main/kotlin/com/bitmovin/player/flutter/json/JsonObjects.kt index 38a18ae0..441ed8b6 100644 --- a/android/src/main/kotlin/com/bitmovin/player/flutter/json/JsonObjects.kt +++ b/android/src/main/kotlin/com/bitmovin/player/flutter/json/JsonObjects.kt @@ -241,6 +241,16 @@ internal class JPlayerViewCreateArgs(override var map: Map<*, *>) : JStruct { val playerId by GetString.require() val hasFullscreenHandler by GetBool.require() val isFullscreen by GetBool.require() + val playerViewConfig by structGetter(::JPlayerViewConfig) +} + +internal class JPlayerViewConfig(override var map: Map<*, *>) : JStruct { + val pictureInPictureConfig by structGetter(::JPictureInPictureConfig) +} + +internal class JPictureInPictureConfig(override var map: Map<*, *>) : JStruct { + val isEnabled by GetBool.require() + val shouldEnterOnBackground by GetBool.require() } // Private property delegator