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

Best practices: ExoPlayer that gets passed between activities/fragments/adapters? #9556

Open
user849651 opened this issue Oct 11, 2021 · 3 comments
Assignees
Labels

Comments

@user849651
Copy link

I have a fairly complicated use case. I'm not looking for specific code, but more high-level technical help about how to best approach this situation.

Here is how I would like my app to work:

  • The main page of my app is a RecyclerView where each item has a video. Only one video should play at a time as the user scrolls down (the first fully visible one).
  • Tapping on a video in the RecyclerView takes you to a second page where I want to continue playing the video where it left off on the first page.
  • When going back from the second page to the first page, the video should continue playing where it left off on the second page.
  • I have several other pages where I would also like to play a video/videos.

From my readings, for performance reasons, it sounds like I should only be creating one instance of ExoPlayer and passing it around.

So my question is, what is the best approach to handling a situation where I should only be creating one instance of ExoPlayer, and then be able to pass it between activities, fragments, adapters, etc.?

Should I create a Singleton where I handle all video player logic and pass that between pages as needed? Or should I go with a different approach?

@claincly
Copy link
Contributor

The best approach would be keep one player instance and use it. If you spin off multiple players, there will be time wasted in things like codec init; and you might run out of available codec.

Please also ref #8189 and #867, there are many useful discussions.

@user849651
Copy link
Author

@claincly

What's the best approach to keeping just one player instance for ExoPlayer? Single-activity architecture, Singleton, something else?

@claincly
Copy link
Contributor

I'm afraid that should be specific to your own application, i.e. do you handle player state changes from many different places, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants