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

Fix playInBackground props in ExoPlayer #833

Merged
merged 8 commits into from
Jun 9, 2018

Conversation

moduval
Copy link
Contributor

@moduval moduval commented Oct 25, 2017

As stated by markusekblad on pull request #563, enabling the flag playInBackground cause the player to not play on startup even if props paused is set to false.

This pull request fix this problem.

Bonus: I updated the readme of android-exoplayer and added instruction on how to use exoplayer instead of default player on android.

@moduval
Copy link
Contributor Author

moduval commented Oct 25, 2017

After some investigation, the sound is killed after a certain time when running in background. We might need to implement something like this:
https://google.github.io/ExoPlayer/faqs.html#how-do-i-keep-audio-playing-when-my-app-is-backgrounded

@cobarx
Copy link
Contributor

cobarx commented May 20, 2018

Yes, pretty sure you will have to setup a service to support background operation.

I know that react-native-track-player has support for this:
https://github.com/react-native-kit/react-native-track-player
Maybe you could use that as a foundation for supporting this.

@zerbfra
Copy link

zerbfra commented May 22, 2018

@moduval I'm working on this too. I have no experience in Android so it's kinda difficult. What @cobarx links is exactly what I'm trying to do.

playerNeedsSource = true;

PlaybackParameters params = new PlaybackParameters(rate, 1f);
player.setPlaybackParameters(params);
}

setPlayWhenReady(!isPaused);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this change made, I'm not sure what it does. When testing with my changes, the video plays automatically even if I switch sources.

@cobarx
Copy link
Contributor

cobarx commented Jun 9, 2018

I've cleaned this up a little, we were re-applying the paused status when playing in the background and then returning to the app.

@moduval There was a change that I'm not sure why it was needed:

@@ -209,12 +206,14 @@ private void initializePlayer() {
             player.setMetadataOutput(this);
             exoPlayerView.setPlayer(player);
             audioBecomingNoisyReceiver.setListener(this);
-            setPlayWhenReady(!isPaused);
             playerNeedsSource = true;
 
             PlaybackParameters params = new PlaybackParameters(rate, 1f);
             player.setPlaybackParameters(params);
         }
+
+        setPlayWhenReady(!isPaused);

What was the reason for this? If it's needed, we can re-add it. When I tested, it worked fine without the change even if I switched to a new video.

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