Abhishek
Abhishek

Reputation: 191

Best way to release and reinitialize exoplayer in RecyclerView

I have two instances of Exoplayer with different mediasources.

Currently

Before initializing either of player. I am checking if any player attached to the surface if yes then releasing the player and initializing again with new operator

if(videoPlayerView.getPlayer() != null) {
             videoPlayerView.getPlayer().release();
             videoPlayerView.setPlayer(null);
 }

videoPlayerView is my PlayerView in SimpleExoPlayer

But after View detached list item becomes black instead of playing again.

Upvotes: 2

Views: 3644

Answers (2)

hamid Mahmoodi
hamid Mahmoodi

Reputation: 718

I strongly suggest you have a single instance of Exoplayer, init in first use and release when activity or fragment (based on your usecase) destroyed

Upvotes: 0

Bin Ding
Bin Ding

Reputation: 41

I used to do similar things with you.You need a global players pool to manager players.You needn't to release it everytime.Just call stop method.And when switch video,just reset source.To make it play instantly witout black, you need to prepare it.When activity is finishing, release all players.

Upvotes: 3

Related Questions