Reputation: 185
Playing a video, and when the app goes to background it should continue playing the audio, and when I reopen it should resume the video respecting where we are in audio.
I'm using exoplayer in a service, I was able to play the audio in background, but when I do the same for video, the audio is playing but when I come back to the app the video is just a black screen, and if I repeat (going to background and coming back to app) the step again it will continue playing video.
As I understood, exoplayer is buffering next frames and the player view got stuck unable to render all frames at once.
I have one instance of exoplayer:
public class ExoPlayerWrapper {
private static SimpleExoPlayer exoPlayer;
public static SimpleExoPlayer getExoPlayer(Context context){
if(exoPlayer == null){
exoPlayer = ExoPlayerFactory.newSimpleInstance(context, new DefaultTrackSelector());
}
return exoPlayer;
}
public static void release() {
if(exoPlayer != null) {
exoPlayer.release();
exoPlayer = null;
}
}
}
The service runs once the view is in foreground
Upvotes: 2
Views: 2511
Reputation: 185
Finally, I did it with, in on pause set playerView.setPlayer(null) and in on resume set playerView.setPlayer(exoplayer_instance)
Upvotes: 0