Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimplePool for Exoplayer #10834

Closed
yoobi opened this issue Dec 5, 2022 · 5 comments
Closed

SimplePool for Exoplayer #10834

yoobi opened this issue Dec 5, 2022 · 5 comments
Assignees
Labels

Comments

@yoobi
Copy link
Contributor

yoobi commented Dec 5, 2022

Describe your question in detail:

Hello, my application use extensively Exoplayer and I wanted to make some improvement for my users ( ~440 000 users with phone from API 21 to API 26).

For context my app is just like Youtube, so users browse between pages which result in an ever-ending cycle of:

  1. creating Exoplayer
  2. setting mediaSource + listeners
  3. playing/pausing
  4. removing listener + releasing Exoplayer

I was wondering if creating/releasing player is more resource-consuming than creating a Pool with 2 instances of Exoplayer? What's your opinion about using a SimplePool<Exoplayer>(2) ?

@marcbaechinger
Copy link
Contributor

Using a pool of player can make sense for some use cases. I wouldn't think about performance in the sense opf resources required to create the players. It is certainly needs a bit more resources to recreate new instances, but I would focus on performance only in the sense of user experience. That is, if you want to play two videos in a RecyclerView or a ViewPager and the surfaces on which the video is rendered are visible at the same time, then you possibly need two players to be able to have at least one frame rendered on each of the surfaces. In general, if your app needs to decode two videos at the same time, you need multiple instances.

However, if you do that you need to take care of some low-level devices possibly do not support multiple instances of the video codec being used at the same time. So it gets a bit more complicated.

In general I would say if there is no need in terms of user experience I would stick with a single instance for simplicity. But I think in your case it can make sense to use a pool.

This is an advanced problem to solve properly and people asked question around this quite a lot. So it also makes sense to search the existing issues a bit to learn how other users solved this problem. An example issue about how to use the player in a RecyclerView is #867.

@yoobi
Copy link
Contributor Author

yoobi commented Dec 6, 2022

Thank you for your detailed answer ! My issue is not really caused by a RecyclerView or ViewPager albeit it can relate in a sense.

Let's say we have VideoPageFragment which creates a new Exoplayer instance in fun onStart() and destroy the instance in onStop(). Therefore there is only one instance of Exoplayer at a time.

  1. User browse toVideoPageFragment to watch a video called: "Building Exoplayer Part 1"
  2. User clicks on button "Next", hence destroying the last VideoPageFragment and creating a new VideoPageFragment with data of the next video.
  3. User close the app

With this simple 3-step example, the user has created and destroyed 2 instance of Exoplayer. Would using a Pool make sense for such a case ?

@yoobi
Copy link
Contributor Author

yoobi commented Jan 16, 2023

Do you have some advice ?

@marcbaechinger
Copy link
Contributor

I understand there is only one fragment active and only one instance playing at a time that can be shared by these fragments. I think in this case I would just have a single instance that is created in the activity, that you can use from the fragment by using ((ExoPlayerHostingActivity)getActivity()).getPlayer(). The fragments lifecycle methods can then be used to set media sources, prepare the player and start playback. Afterwards the player is pause, stopped and released. For such a use case without overlapping playback a single instance sounds sufficient.

@yoobi
Copy link
Contributor Author

yoobi commented Jan 16, 2023

I'm ashamed to say I didn't think of that because this is simple and brilliant. I'll go with that instead of doing a pool.

Thanks

@yoobi yoobi closed this as completed Jan 16, 2023
@google google locked and limited conversation to collaborators Mar 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants