Reputation: 1345
I use two different instances of PlayerView (com.google.android.exoplayer2.ui.PlayerView) in two fragments in my app. Both of these Playerview instances use the same SimpleExoPlayer instance for the player. In fragment1 the playerView1 works fine and also when I go to the fragment2 the playerView2 which uses the same SimpleExoPlayer instace works fine. The problem is when I go back to the fragment1 the playerView1 doesn't show anything. I think before going back to the 1st fragment I should release the player of the playerView2 but I don't know how.
In fragment1 (kotlin):
playerView1.player = myGlobalSimpleExoPlayer
In fragment2 (kotlin):
playerView2.player = myGlobalSimpleExoPlayer
Upvotes: 3
Views: 3572
Reputation: 1345
After trying different methods finally I found the solution. I share the solution here maybe it would be useful for others with the same problem.
In each fragment before setting the player of the PlayerView I set null value for the player (You should do this each time you switch the fragments, not only the first time):
playerView.player = null // add this before setting the actual player
playerView.player = myGlobalSimpleExoPlayer
Upvotes: 7