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

feat: automatic PiP animation #648

Conversation

Natanel-Shitrit
Copy link
Contributor

@Natanel-Shitrit Natanel-Shitrit commented Feb 2, 2024

Make transitions to PiP mode smoother from gesture navigation:

pip.mp4

Demo from: https://developer.android.com/develop/ui/views/picture-in-picture

For Android 12 and newer, only tested on android 14.

@cd16b
Copy link
Contributor

cd16b commented Feb 2, 2024

Hi, I added PiP support last year.
However, I removed the setAutoEnterEnabled() feature because of two problems.

  • It should only be enabled when the video is playing, like on YouTube. So, you have to update it every time the playback status changes, and I wasn't able to make it work correctly.
  • MPV player: for a smoother transition, it's better to use the getGlobalVisibleRect() function, but unfortunately, it's not available for MPV player at the moment (that's why it's using that long unnecessary code to get SourceRectHint), but it can be used for Exoplayer.

Last I recommend calling

binding.playerView.useController = false
binding.playerView.findViewById<Button>(R.id.btn_skip_intro).isVisible = false
playerGestureHelper?.updateZoomMode(false)

inside pictureInPicture() to hide all player controls before the animation begins or at least when using the PiP button.
I'm trying to adress all this issues, but I do not have much time.

@Natanel-Shitrit
Copy link
Contributor Author

  • It should only be enabled when the video is playing, like on YouTube. So, you have to update it every time the playback status changes, and I wasn't able to make it work correctly.

It's working fine when paused, am I missing something? 😅

  • MPV player: for a smoother transition, it's better to use the getGlobalVisibleRect() function, but unfortunately, it's not available for MPV player at the moment (that's why it's using that long unnecessary code to get SourceRectHint), but it can be used for Exoplayer.

Is that something that effects the animation?
MPV player is animated correctly with the current state of the code.

Last I recommend calling

binding.playerView.useController = false
binding.playerView.findViewById<Button>(R.id.btn_skip_intro).isVisible = false
playerGestureHelper?.updateZoomMode(false)

inside pictureInPicture() to hide all player controls before the animation begins or at least when using the PiP button.

I see what you are talking about, the callback is firing only after the state change, but it's really hard to notice, so I guess it's not really a big deal.

@cd16b
Copy link
Contributor

cd16b commented Feb 3, 2024

It's working fine when paused, am I missing something? 😅

I believe that if the video isn't going to be played (playWhenReady == false), the app should just exit instead of entering PiP mode similar to how it works on YouTube.
(I have fixed this issue in my pip-autoEnterEnable branch)

Is that something that effects the animation? MPV player is animated correctly with the current state of the code.

No, but the animation looks bad, it zooms out after entering PiP. (It's not a significant issue; it's also present on YouTube)

I see what you are talking about, the callback is firing only after the state change, but it's really hard to notice, so I guess it's not really a big deal.

I tried to fix this in my pip-autoEnterEnable branch, preparing pip in an external function.

Sorry for using YouTube as my main reference, but is the app where I think PiP is better implemented 😅

@jarnedemeulemeester
Copy link
Owner

Okay so I rebased this on top of main and fixed the merge conflict with the recent zoom fix.

I also added the fix for disabling the pip gesture when content is paused. I took the implementation from @cd16b but modified it a little bit.

While using a preparePip function before calling enterPictureInPictureMode creates a smoother animation by first disabling the controls and resetting the zoom mode. I don't think it's worth it because in my opinion it make the code less readable.

Also fixed a crash when gestures are disabled and entering pip using the button.

This PR + my changes have been tested on Android 9 and Android 14.

@jarnedemeulemeester jarnedemeulemeester merged commit 42df641 into jarnedemeulemeester:main Feb 3, 2024
2 checks passed
@Natanel-Shitrit Natanel-Shitrit deleted the feature/smooth-pip branch February 3, 2024 21:09
ghost pushed a commit to pruthvi-21/findroid that referenced this pull request Jul 22, 2024
* Add automatic PiP animation

* Fix linting

* Fix linting

* chore: fix merge conflict

* fix: disable pip gesture when media is paused

* fix: crash when gestures are disabled

* fix: keep auto enter enabled after using button

---------

Co-authored-by: Cd16d <98320806+cd16b@users.noreply.github.com>
Co-authored-by: Jarne Demeulemeester <jarnedemeulemeester@gmail.com>
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