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

Feature/android pip #1776

Closed
wants to merge 12 commits into from
Closed

Conversation

matejpolak
Copy link

Provide an example of how to test the change

In order to test this change, you should follow all new steps listed in readme under picureInPicture props:

  • Add following to the AndroidManifest.xml -> MainActivity:
  android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout"
  android:resizeableActivity="true"
  android:supportsPictureInPicture="true"
    // To let JS knows about PIP mode change. 
    override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration?) {
       super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
       val intent = Intent("onPictureInPictureModeChanged")
       intent.putExtra("isInPictureInPictureMode", isInPictureInPictureMode)
       this.sendBroadcast(intent)
    }
    
    // To trigger PIP mode by pressing `Home` or `Recent` buttons
    override fun onUserLeaveHint() {
       val intent = Intent("onUserLeaveHint")
       this.sendBroadcast(intent)
       super.onUserLeaveHint()
    }
        
    // To close and kill the app when closing PIP window.
    override fun onStop() {
       super.onStop()
       finishAndRemoveTask()
    }

Afterwards, set pictureInPicture prop, or press Home/Recent HW button.

Describe the changes

So far PIP mode has been supported only on iPad. From now on, it should be working also on all Android Phones and Tablets running Oreo at least. This implementation includes:

  • Ability to toggle PIP mode by setting pictureInPicture prop.
  • onPictureInPictureStatusChanged prop callback returning PIP state same as iOS does.
  • Ability to turn on PIP mode by pressing Home/Recent HW button.
  • Previous / Pause/Play / Next PIP window buttons.
  • Implementation of closing and killing the entire app when closing PIP window.

android-PIP

@dylancom
Copy link

Why isn't this merged yet?

@Spoutnik97
Copy link

Hi !
Is there an update of the pull request ?

@matejpolak
Copy link
Author

Hello everyone, let me take a look at this PR again, solve the conflicts, and then we are ready for reviews and eventually for merging. Anyways I would need someone to give a green light.

I think I should be able to get back to this somewhere this week.

@mbrimmer83
Copy link

Hi,
Any updates on this pull request?
Thanks

@michael-kiley-verified
Copy link

Hi all,
This looks like good work and is a feature I would really love to get access to. Is this still active?
Thanks!

@KingAmo
Copy link

KingAmo commented Mar 5, 2021

@nickfujita what do you think about this pr

@victoromarques
Copy link

How do I apply this change to my project? how do i install this update?

@hueniverse hueniverse added stale Closed due to inactivity or lack or resources and removed ExoPlayer labels Apr 22, 2022
@hueniverse hueniverse closed this Apr 22, 2022
@jrhager84
Copy link

How do we implement this in our react-native-video projects? It seems to be great. Why hasn't this been merged?

@hueniverse
Copy link
Contributor

I automatically closed PRs and issues that were stale. We can reopen if there is interest and resources to review and test. If you are interested in helping getting this PR through, I'm happy to reopen. Merging this would require 3 people to review, test, and approve it.

@jrhager84
Copy link

I automatically closed PRs and issues that were stale. We can reopen if there is interest and resources to review and test. If you are interested in helping getting this PR through, I'm happy to reopen. Merging this would require 3 people to review, test, and approve it.

I would, actually. I'll see if I can carve some time. 😎👍

@freeboub
Copy link
Collaborator

Code looks good, but I am afraid this change is not really expected in react-native-video...
I agree this is a must have feature ! :)
But pip is not be linked to react-native-video (google maps also supports pip)
I have just publish a fork of rn-android-pip here: https://github.com/iFeelSmart/rn-android-pip/
With this project I am able to use pip in any app (including react-native-video).

For exemple, if tomorrow you want to do pip with react-native-youtube, (https://www.npmjs.com/package/react-native-youtube) you can have issues to make multiple pip handling bindings ...

@jrhager84
Copy link

jrhager84 commented Apr 23, 2022

Code looks good, but I am afraid this change is not really expected in react-native-video... I agree this is a must have feature ! :) But pip is not be linked to react-native-video (google maps also supports pip) I have just publish a fork of rn-android-pip here: https://github.com/iFeelSmart/rn-android-pip/ With this project I am able to use pip in any app (including react-native-video).

For exemple, if tomorrow you want to do pip with react-native-youtube, (https://www.npmjs.com/package/react-native-youtube) you can have issues to make multiple pip handling bindings ...

What about pip for ios? Wouldn't react native youtube support that as well? In my mind it would make sense to handle pip in rn video because it also supports ios.

@freeboub
Copy link
Collaborator

I agree that ios pip is already handle by react-native-video so it make sens to support it on android.
For react-native-youtube, i don.t think they support...
I just want to highlight it can cause conflicts with other implementations...

@freeboub
Copy link
Collaborator

In other words, it is very useful for quick integration, but it doesn't fullfil all expected requirements of an advanced android application :)

@jrhager84
Copy link

In other words, it is very useful for quick integration, but it doesn't fullfil all expected requirements of an advanced android application :)

What advanced requirements are you referring to? Is it something that other package can do? Maybe I just don't know enough about android pip to weigh in.

@TomMichalkevic
Copy link

I'll make some time to test this tomorrow ;) Let's get this reviewed and merged.

@TomMichalkevic
Copy link

TomMichalkevic commented Apr 25, 2022

So I've tested it a bit and I'm not sure it works the way it should:
image
The app crashes now each time there is an attempt to play any video with the added pictureInPicture prop.
If I remove the prop, it works fine. As in, no PiP, but playback works again.

&& packageManager
.hasSystemFeature(
PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
long videoPosition = player.getCurrentPosition();

Choose a reason for hiding this comment

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

This line should be removed. The variable is not used anywhere and causes crashes.

@TomMichalkevic
Copy link

TomMichalkevic commented Apr 25, 2022

With the line removed above it continues on working, but the PiP floating window disappears.
Here's what I get from logcat:
MainActivity has leaked window DecorView@ca3e234[] that was originally added here at android.view.ViewRootImpl.<init>(ViewRootImpl.java:733) at android.view.ViewRootImpl.<init>(ViewRootImpl.java:717) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:399) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:109) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4535) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

@hueniverse
Copy link
Contributor

@TomMichalkevic Thanks for the review.

@matejpolak Are you still interested in getting this meged?

@paulohc
Copy link

paulohc commented Jul 7, 2022

Hello @hueniverse!
Is there still any chance to reopen and merge this PR?

@hueniverse
Copy link
Contributor

@paulohc there is no point to reopen it because it needs to be rebased. If you want to do the work and open a new PR with these changes against master, it will get reviewed. Someone needs to do the work.

@watadarkstar
Copy link

watadarkstar commented Jun 1, 2023

Here is the Java code for anyone who needs it as the instructions were written in Kotlin for the MainActivity:

import android.content.Intent;
import android.content.res.Configuration;

...
    
@Override
protected void onStop() {
    super.onStop();
    finishAndRemoveTask();
}

@Override
protected void onUserLeaveHint() {
    super.onUserLeaveHint();
    Intent intent = new Intent("onUserLeaveHint");
    this.sendBroadcast(intent);
}

@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
    super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
    Intent intent = new Intent("onPictureInPictureModeChanged");
    intent.putExtra("isInPictureInPictureMode", isInPictureInPictureMode);
    this.sendBroadcast(intent);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Platform: Android stale Closed due to inactivity or lack or resources
Projects
None yet
Development

Successfully merging this pull request may close these issues.