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

Conversation

zigavehovec
Copy link
Contributor

@zigavehovec zigavehovec commented Dec 18, 2023

Description

There is currently no way to get notified from the OS that PiP mode has been activated.

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 issue, this PR introduces a ComponentCallbacks instance registered to an instance of the Activity, this way we can get notified about configuration changes.
Edit: unfortunately, component callbacks don't work for some Android versions (tested on Android 10 with FlutterFragmentActivity). My suspicion is that it's an issue in Flutter's activity - since one can also observe activity getting a red color overlay.

The configuration change listening is now done by overriding view's onConfigurationChanged. Since Flutter's PlatformView isn't actually an Android View we have to add a blank view to the PlayerView in order to be able to override the mentioned function.

In combination with activity.isInPictureInPictureMode we can imitate Activity's onPictureInPictureModeChanged.

This PR is prework for PiP implementation.

Changes

  • Added and registered a ”fake" onPictureInPictureModeChanged callback

Tests

Checklist (for PR submitters and reviewers)

  • 🗒 CHANGELOG.md entry for new/changed features, bug fixes or important code changes
  • 🧪 Tests added and/or updated
  • 📢 New public API is fully documented

@zigavehovec zigavehovec changed the base branch from main to PFL-83/add-lifecycle-handling December 18, 2023 16:21
…ation-change-handling

# Conflicts:
#	android/src/main/kotlin/com/bitmovin/player/flutter/FlutterPlayerView.kt
@zigavehovec zigavehovec changed the title Pfl 83/add configuration change handling Introduce configuration change handling (PiP #2) Dec 18, 2023
@zigavehovec zigavehovec changed the title Introduce configuration change handling (PiP #2) Introduce onPictureInPictureModeChanged to FlutterPlayerView (PiP #2) Dec 18, 2023
@zigavehovec zigavehovec self-assigned this Dec 18, 2023
@zigavehovec zigavehovec requested review from krocard, strangesource and testcenter and removed request for krocard December 18, 2023 16:43
@zigavehovec zigavehovec marked this pull request as ready for review December 18, 2023 16:44
Copy link
Contributor

@testcenter testcenter left a comment

Choose a reason for hiding this comment

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

lgtm 👍

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 🙂

…ation-change-handling

# Conflicts:
#	android/src/main/kotlin/com/bitmovin/player/flutter/FlutterPlayerView.kt
@zigavehovec
Copy link
Contributor Author

I found an issue with the component callbacks on Android 10 and had to change the implementation. Please review again.

Copy link
Contributor

@strangesource strangesource left a comment

Choose a reason for hiding this comment

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

Looks good, just some minor NIT/ a question.

@@ -111,6 +119,28 @@ class FlutterPlayerView(
sink = null
}

private fun PlayerView.setOnPictureInPictureModeChanged(callback: (Boolean, Configuration) -> Unit) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private fun PlayerView.setOnPictureInPictureModeChanged(callback: (Boolean, Configuration) -> Unit) {
private fun PlayerView.setOnPictureInPictureModeChangedCallback(callback: (Boolean, Configuration) -> Unit) {

Where will this function be called from? I can't see any usage yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

zigavehovec and others added 3 commits December 21, 2023 14:10
…yerView.kt

Co-authored-by: Lukas Knoch-Girstmair <strangesource@users.noreply.github.com>
…yerView.kt

Co-authored-by: Lukas Knoch-Girstmair <strangesource@users.noreply.github.com>
@zigavehovec zigavehovec mentioned this pull request Dec 21, 2023
3 tasks
Base automatically changed from PFL-83/add-lifecycle-handling to main December 22, 2023 13:19
@zigavehovec zigavehovec merged commit 9dc6459 into main Dec 22, 2023
4 checks passed
@zigavehovec zigavehovec deleted the PFL-83/add-configuration-change-handling branch December 22, 2023 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants