Skip to content

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

@user849651

Description

@user849651

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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions