-
Notifications
You must be signed in to change notification settings - Fork 6k
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
How to use ExoPlayer in a ListvVew or RecyclerView? #867
Comments
You should keep track of a reference to the ExoPlayer and try to reuse the player for every item in the ListView by just loading new media on the player. |
Thank you RikHeijdens. Do you mean, I should make only one instance of ExoPlayer and switch the video link at properly timing? What should I do, If I want to play two or three videos at the same time, because the height of the surfaceView is fixed and how many rows will be showed on the screen at the same depends on the height of the devices. |
If you want to play multiple video's, for instance two at the same time you should instantiate 2 ExoPlayers, with 2 different SurfaceViews. And yes you switch the video as soon as the 'recycled' item moves out of the screen. |
@RikHeijdens Supports two hard decoding at the same time for the device? |
On my Nexus 5 I can play up to 6 video's at the same time, however you don't want to instantiate so many players because the performance will degrade pretty quickly after two instances. |
BTW: In this case, not all devices are supported. |
Thank you for your advice, I decided to try to use only one ExoPlayer. And I will upload some sample code, and hope get more advice. |
Here is my source code, although it doesn't work very well, but I think it's the right way to do this. In this customized RecyclerView(ExoPlayerVideoRecyclerView), I make only one SurfaceView for video play, and add to the row root view and remove it every time I need. At this time I got these 3 problems.
About problem 1, I tried this code to reset the ration, but it doesn't seem work.
From here is the code abstracted form next sample:
|
@NatsumeReiko ,how to goto fullscreen when click the item of the listview? Do you have any idea? |
I have a use case (for multiple exoplayers) where there can be TextureViews in each page of viewpager, minimum 3 exoplayers would be allocated, one per textureview(in each page). Although I play only a single exoplayer at a time(the one belonging to textureview of focused page) and rest are in paused state, |
@jayshah123 I think you could see this repo https://github.com/xingstarx/InkeVerticalViewPagerLive I hope that can help you |
@NatsumeReiko that's an interesting solution, but if you move the SurfaceView to another container, you would lose the paused state thumbnail if you need to resume the video while the user scroll. Do you think reusing surfaceView is much more performant than just reusing the player? |
I'm facing almost the same challenge. So I would like to know if it is feasable to use multiple SurfaceViews in a ListView and just switch the Player between them or is it better to reuse the same surface when I need it? Thanks |
Check out https://github.com/eneim/Toro |
NatsumReiko or anyone , please help me in playing Hls Video inside recyclerview , i want to play Hls videos inside recyclerview, Please help me with code, i would be thankful for you sooo much. |
I am facing the same problem with Another problem I noticed with the player instance reuse is that if 2 items are visible at the same time, item A is playing, and I start playing item B, then item A will be "reset" to a default state with the total time set to 00:00 and the current "thumbnail" image (video) removed along with the controllers, which seems like a really bad UX. My question is: what are the performance / networking / bandwidth effects of using more than 1 players, but playing only one at the same time (it would use some kind of an "obtain" mechanism by creating new player if there isn't an available one)? So if the user starts playing item B by pressing the play button, item A would pause. I'm afraid that pausing the players would not be enough because they would still keep buffering / holding data, but stopping them resets the current state, which means back to square one. |
Thank @artworkad for mentioning my library :D. FYI @Gericop I have been struggling a long time with the same idea with you. I finally end up with the belief that ExoPlayer instance will not consume your CPU and much of your network as long as you don't ask it to (= calling player.setPlayWhenReady(true)). It may start fetching some meta data at preparing, but it should be fine with just that. Having a Singleton Player will be scary (good for performance though). You can learn from how Youtube Player API doing so (closed source, yep, but enough study may turn to something I guess). |
Your Toro library @eneim suffers from thread locking and slow performance when scrolling the recycler. Particularly when you fling the RecyclerView. In my own testing, I have found that using a single player instance is much better. It removed all my issues with thread locking. I guess the players are contending for Codec access, or some other issue is occuring. This happens even if only one player is playing at a time. The best approach I've found is to:
This method is working very well for me, I get a very fast experience. |
You are right about the issue of having multi ExoPlayer instance in the library. Lately I also investigate in the case of using Single/Limited ExoPlayer instances. Your approach gonna be so much helpful. (It turns out that, to make it highly abstraction and easy to integrate, many works need to be done). |
I have also found that you can further increase performance by using a TextureView instead of SimpleExoPlayerView, and only create one TextureView object instead of one per viewholder. In your Adapter or Activity, store a single TextureView object, and pass it to the ViewHolder that is playing at runtime. Reuse the same TextureView item for each viewholder that is playing. I cannot believe how much smoother my application runs this way. |
Just an update to TextureView re-use in RecyclerView, it seems to be quite buggy when removing a TextureView from it's parent and moving it to a new View. If you want to get that working, the better approach is to hold the TextureView inside the Activity view, and overlay the recyclerview on top. It's a difficult approach, but if you move the TextureView between parents, it seems to end up displaying a black screen on resize or program resume. It's actually still quite fast to have a TextureView for each Viewholder, so that seems to be a simpler option. |
Hi, when i switch the exoplayer from recycler view to a dialog with the help of getplayer() and setplayer() method then frames are hang for some sec and sometimes audio is audible but frames are not see please tell me how to resolve this issue with toro |
It's this very old issue which is still open. Is there a proper solution for using ExoPlayer is ListView or RecyclerView? A working sample would be great help for a beginner like me. @ojw28 @andrewlewis |
Can someone please help me to use ExoPlayer with ViewPager2 using RecyclerViewAdAPTER? |
Hi guys, I really want only thing pls:
I solve all other problems, only left this one to be perfect. And i understand that no one here have any obligation. Project page: |
Here's a simple app showing how I've been doing it with ViewPager2: |
The performance are good? |
It loads videos from LocalStorage not from Internet so performance will be
good in offline mode but for online i can't tell because it need to pre
cache first portion of data
… |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Why do you even call this "clean". I mean you are creating ExoPlayer instance multiple times. And what does "clean" really mean here? |
Just to point out the pitfall here. https://github.com/nihk/videopager/blob/caf0f3c049d713cff8bba3e11798b3f99d62e606/exo/src/main/kotlin/com/exo/players/ExoAppPlayer.kt#L101. Why do you treat |
I'm not sure what you're asking. There's no treatment nor dependency on Player.prepare() being executed synchronously in that file. |
PiperOrigin-RevId: 590142275
PiperOrigin-RevId: 590142275
I have created a singleton exoplayer class where i am attaching and detaching playerview based on recyclerview positions. I will share my code soon. |
now no one using recyclerview try jetpack compose. |
Please, share. |
99% of code of new exoplayer (media3) written in java even we are using Core java in our production app without using compose in most of the cases |
I want to use ExoPlayer in a RecyclerView as a part of row item.
I want to make a customer view and wrap the ExoPlayer in that view.
Do you have some advice?
Thank you!
The text was updated successfully, but these errors were encountered: