Skip to content

Commit

Permalink
chore: use picture in picture handler
Browse files Browse the repository at this point in the history
  • Loading branch information
zigavehovec committed Dec 19, 2023
1 parent 5ae79c6 commit 622f267
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,6 +60,7 @@ class FlutterPlayerView(

override fun onLowMemory() = Unit
}
private var pictureInPicturehandler: PictureInPictureHandler? = null

private val activityLifecycle =
(activity as? LifecycleOwner)
Expand Down Expand Up @@ -90,6 +93,10 @@ class FlutterPlayerView(
),
)
}
if (playerViewCreateArgs.playerViewConfig?.pictureInPictureConfig?.isEnabled == true) {
pictureInPicturehandler = FlutterPictureInPictureHandler(activity, player)
playerView.setPictureInPictureHandler(pictureInPicturehandler)
}
}

activityLifecycle.addObserver(activityLifecycleObserver)
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 622f267

Please sign in to comment.