2

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.

Abhishek
  • 181
  • 2
  • 12

2 Answers2

3

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.

Bin Ding
  • 41
  • 1
  • 1.Create a pool manager players,like class ExoplayerPlayModel { bool isAvailable; // whether this player is using bool hasPrepare; // whtehter the player has been prepared SimpleExoPlayer simpleExoPlayer; // cache player; String url; // media source String keyId; // use to find } manage a list, like List, not more than 5 2. define prepare, getPlayer method in the manager 3.when switching player, just call stop, don't call release, only when your activity call onDestroy, call release. – Bin Ding Apr 03 '20 at 06:38
0

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

hamid Mahmoodi
  • 690
  • 4
  • 16