Using ExoPlayer in a RecyclerView - the official way

Viewed 3487

I wanted to know if there is a working sample for using ExoPlayer in a RecyclerView ? All examples I have found is based on using ExoPlayer with one view (PlayerView) but there is no sample for beginners out there demonstrating how to use ExoPlayer in a RecyclerView environment where the views can get attached or detached from the visible screen.

Why is that so ? Why is it so difficult to integrate ExoPlayer into the Android Framework ecosystem so that we can use it without re-inventing the wheel. It's fair to assume that listing videos in a list is a common requirement but there is no guideline or whatsoever to help Android App developers. The very few "hints" and "solutions", living in the internet out there, are in most cases just a pain in the ass.

The only useful sources I have found are these:

  1. github discussion thread (which I don't use because everytime I use "non-official" solutions, my apps crash for some reason, therefore I always prefer "official" solutions provided by Google)
  2. and this blog entry (which I can't use because I use the latest Android Architecture Components like Paging with PagedListAdapter, Room for offline caching, LiveData, etc. etc. which do not fit very well with that approach).
3 Answers

I have just do similar things in our app.I may play 50 videos in a page and can turn page, every page can play many video.We use viewpages and keep three playerview and 5 exoplayers.One thing you need to keep in mind is that, the players must be managed globally.You need to put them in a pool, acquire it and put it in pool.use setPlayer() method to replace player, view and player are seperate.

AFAIK there is no official solution yet. I'm one of the commenters in the Github Issue you mention above, and I created https://github.com/eneim/kohii for this similar purpose. If you are still searching for a solution, please give it a try.

Related