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

Exoplayer black screen when scrolled through recyclerview #7750

Closed
punitagoel2403 opened this issue Aug 13, 2020 · 8 comments
Closed

Exoplayer black screen when scrolled through recyclerview #7750

punitagoel2403 opened this issue Aug 13, 2020 · 8 comments
Assignees
Labels

Comments

@punitagoel2403
Copy link

I am using exoplayer in recyclerview. It loads well if I click on independent video from the list, but if I swipe and move to previous or next video only audio is playing, and the video is black throughout the duration. Only first clicked video shows the display. It is surely not a loading problem, since I am using caching and even after caching it behaves same way.

Note: In rarest of occasions, it works fine for one swipe.

I am pausing previous and preparing n playing next video in onViewAttachedToWindow method

@vikasgill
Copy link

vikasgill commented Aug 13, 2020

@punitagoel2403 What surface type are you using? Is it a SurfaceView or TextureView? Also, what Android version you are using?

@punitagoel2403
Copy link
Author

@vikasgill I am not overriding any value. Just using the default basic structure. I am testing on Android 10.

@punitagoel2403
Copy link
Author

punitagoel2403 commented Aug 14, 2020

Thanks @vikasgill for hinting it out. On further exploration, I understood, I had to set the player in method onViewAttachedToWindow rather than onBind, since I am using singleton player object. It is working fine now. Thanks once again. :)

@punitagoel2403
Copy link
Author

punitagoel2403 commented Aug 21, 2020

I am reopening this issue. I just noticed there is another problem occurring after resolving the previously stated issue.
The previous issue was resolved by setting the player in onViewAttachedToWindow before playing the video. This worked fine. But now another issue has arisen. The video on any item once played if scrolled back doesn't show on the same item.

For eg: I have 10 items in recyclerview.
I start with 5th video. It plays well.
I scroll down to 6th video. Plays well.
goes back to 5th. only audio with black screen. I noticed, the 5th video is actually playing in 6th itemview (which is not visible on the screen).
I scroll up to 4th video, plays well.
I scroll up to 3rd video, plays well.
Goes down to 4th, only audio with black screen. I noticed, the 4th video is actually playing in 3rd itemview (which is not visible on the screen).

I have checked the holder position, it is correct, so selected view holder is correct.

So, if one holder has played a video, next time it is not playing the video again, the video plays in previously newly used holder only. I also tested this with overriding onScrollStateChanged assuming it could be some recyclerview issue. But still the same results.

Note: I am using singleton object of player.

@punitagoel2403
Copy link
Author

Any updates?

@vikasgill
Copy link

@punitagoel2403 Could you please share what you are actually doing. I am in doubt you are setting the wrong surface instance.

@punitagoel2403
Copy link
Author

I am using singleton class for Exoplayer, and independent playerview for each item in a recyclerview. I am setting the player to playerview in onViewAttachedToWindow based on current position.

Exoplayer.playVideo(false, null); // pauses the video, setPlayWhenReady(false)

holder.playerView.setPlayer(Exoplayer.getPlayer()); // set the player to current holder playerview

Exoplayer.playVideo(true, mMediaSourceMap.get(holder.getAdapterPosition())); // setPlayWhenReady(true) and prepare the player( player.prepare(mediaSource);) Media sources per url is prepared in advance

This work fine, if I am scrolling to a holder used for the first time. But if I try to go back to the watched video, the player runs in last played playerview.

Giving the example again
eg: I have 10 items in recyclerview.
I start with 5th video. It plays well.
I scroll down to 6th video. Plays well.
goes back to 5th. only audio with black screen. I noticed, the 5th video is actually playing in 6th itemview (which is not visible on the screen).
I scroll up to 4th video, plays well.
I scroll up to 3rd video, plays well.
Goes down to 4th, only audio with black screen. I noticed, the 4th video is actually playing in 3rd itemview (which is not visible on the screen).

I have checked the holder position, it is correct, so selected view holder is correct.
Note: I am displaying the view full screen, So at a time only one view is visible on the screen. PagerSnapHelper

Please let me know if you need more details.

@punitagoel2403
Copy link
Author

Closing. New similar issue raised in #8093

@google google locked and limited conversation to collaborators Dec 22, 2020
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

4 participants