Black screen sometimes when switching the same player from a playerView to another in recycler view
Hi,
I sometimes get a blackscreen on the new player view when switching from another player view with a new media source in recycler view. Note that audio plays correctly but the video is blacked out with the same view aspect ratio of the old player view. I am stopping the player when I switch to the new player view, and this is how I play it:
public void play (Uri uri){
if(playingUri != null && playingUri.equals(uri)){
Timber.d("Exo Player already playing!");
return;
}
playingUri = uri;
MediaSource mediaSource = new ProgressiveMediaSource.Factory(getDataSourceFactoryInstance(context))
.createMediaSource(uri);
playerView.setPlayer(player);
player.setPlayWhenReady(true);
player.prepare(mediaSource, true, false);
}
ANY HELP WOULD BE APPRECIATED!
I remember facing such an issue previously, for reaching limits of media codecs supported by the device. I had to change my implementation to invoke fewer instances of exoplayer.
I think it's mentioned in https://github.com/google/ExoPlayer/issues/273
I guess this is what's causing my problem, but the thing is that I don't intend to run multiple instances at the same time. All I am trying to do is reuse the same instance instead of creating a new ExoPlayer instance each time which is causing stutters and frame drops while scrolling in my recycler view. Any ideas?
What are you calling to make the player stutter/dropping frames? Can you share your systrace with me?
I understand with stuttering you are referring to the main thread being occupied too long, while frame drops are caused by something on the playback thread?
Some random ideas which come to mind:
- Switching a player from on surface to another and preparing the player with a new media source is likely to cause a black frame. This is specifically likely if the media source needs to download data first. I'd advice to have a bitmap overlay on the player view. You can then remove the overlay at the moment when VideoRendererEventListener.onRenderedFirstFrame() is called.
- You should avoid calling release() in case you do this because it is a blocking call. Besides this all calls are async in a sense that a message is sent to the playback thread.
- It's worth thinking about caching so if a users scrolls back data is available in the cache.
Yes, the stutter while scrolling is happening when I create a new instance of SimpleExoPlayer which is causing a huge load on the main thread, which I am not sure why. This is the link of my Player Class: https://pastebin.com/fXvLxZB1 What I am currently doing is reusing the same instance in my recycler view while I am still in the same activity. Which is also causing load on the main thread.
Closing for now. Please re-open if you have new insights.