Skip to content
Advertisement

Exoplayer multiple instances when loading new fragments

I am creating a radio streaming app for a friend. I decided go down the Exo player route. Everything works fine, apart from if I load a new fragment or turn the screen round. Then I get a new instance of Exo player that starts behind the original. It can get really messy – how can I avoid this?

Here is my code. I open the fragment using:

JavaScript

This is how I call Exo player:

JavaScript

This is an example of the fragment I’m opening:

JavaScript

This is my main activity where I call the fragments from:

JavaScript

Advertisement

Answer

According to your code above currently in your onStop() method you initialise a new instance of SimpleExoPlayer instead of release it. You initialize the player in the onStart() or onResume() methods depending on the API level and release the created player in your onPause() or onStop() methods.

Currently you have:

JavaScript

Change it to:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement