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

Android video plays on load regardless of paused flag (device/release only) #494

Closed
briancalvium opened this issue Feb 14, 2017 · 12 comments

Comments

@briancalvium
Copy link

briancalvium commented Feb 14, 2017

using 1.0.0
I have the following in JS:

<RNVideo
  ...
  paused={true}
/>

in debug, this works as expected - user sees first frame of video, and video is paused. In release (on a Samsung S6), the video plays.

I added a log statement to ReactVideoView:

if (mPaused) {
            if (mMediaPlayer.isPlaying()) {
                pause();
            } else {
                Log.d("VIDEO", "Attempted to pause when not playing!");
            }
        } else ...

and am seeing that message in LogCat.

@sarmadka
Copy link

I confirm this. Having the same issue. For me the video is playing even in debug mode in the simulator.

@DevAlien
Copy link

I found out the same issue, Videos play regardless of paused and of rate={0}

@pepavesely
Copy link

Same problem.

@davidjeffries
Copy link

Same issue as: #484

Workaround, change the state on video load:

this.state = {paused: false};

Component:

paused={this.state.paused}
onLoad={() => {
  this.setState({
    paused: true
  });
}}

@ghost
Copy link

ghost commented Mar 21, 2017

ROOT CAUSE
I think I found the possible root cause. In ReactVideoView, the onHostResume is called soon after the player is initialized and launched. What I believe is an unintended consequence is that whatever value was assigned to mPaused gets overwritten by the value of mActiveStatePauseStatus (which is always false when the class is initialized). This happens in the onHostResume when the setPausedModifier method is called.

SOLUTION
In the ReactVideoView class, you need to initialize mActiveStatePauseStatusInitialized not to false but to the value of the paused property that comes down from React Native. To achieve that:

  1. add this in the constructor:
    private boolean mActiveStatePauseStatusInitialized = false;
  2. add this in the setPausedModifier method, after the first line of code:
    if ( !mActiveStatePauseStatusInitialized ) {
    mActiveStatePauseStatus = mPaused;
    mActiveStatePauseStatusInitialized = true;
    }

@gorjanz
Copy link
Contributor

gorjanz commented Mar 21, 2017

I can confirm that @devmaster72 solution works. Is there a pull-request already, or should I create one?

Thank you!

@xavieramoros
Copy link

I have the same issue as well, solved using @davidjeffries solution to avoid initial paused flag problem.

But I have a similar problem when my app goes to background and then becomes active again, the video plays despite being paused previously (with the paused prop being true based on state). My state doesn't change. Looks like it's related but not sure.

@ghost
Copy link

ghost commented Mar 22, 2017

@xavieramoros, I tested that scenario in my app. Setting the paused prop in the onLoad does not address the root cause of the problem and leaves you exposed to the issue when you background the app and then foreground it. The issue is the one that I was referring in my previous post above. If you use what @gorjanz has committed yesterday all the issues will go away (make sure you remove the setting of the paused prop in the onLoad. Just set the paused prop of the video component to whatever you want it to be)

@xavieramoros
Copy link

Thanks @devmaster72 , I tested @gorjanz fix (9ce1f4b), both cases (background/foreground and initial props) work as expected.

My problem now is that I'm using android-exoplayer to avoid the issue of blocking UI while video is loading: #451, which is even worse. Not sure how to have both problem fixed.

@duhseekoh
Copy link
Contributor

@xavieramoros - Are you saying this fix doesn't work when using exoplayer?

@xavieramoros
Copy link

Sorry for the misunderstanding and late reply @duhseekoh, I was just mentioning that there was still another issue, related to the UI being blocked while loading the video #451.

ExoPlayer probably doesn't need this fix.

@waheedakhtar694
Copy link

Can anyone please tell me, Is this solution will work on exo-player too?
I am having same issue on exo-player

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

No branches or pull requests

10 participants