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

Only audio in black screen, no video in RecyclerView #10010

Closed
1mean opened this issue Feb 27, 2022 · 2 comments
Closed

Only audio in black screen, no video in RecyclerView #10010

1mean opened this issue Feb 27, 2022 · 2 comments
Assignees
Labels

Comments

@1mean
Copy link

1mean commented Feb 27, 2022

description

use the latest Exoplayer2.17.0 in RecyclerView,some items play video normally,some items only have audio but no video on a black background area!!all other views of RecyclerView item are displayed correctly ,only the video play is wrong

my code is :

  • 1、init exoplayer in fun onStart() :
val mPlayer = ExoPlayer.Builder(mActivity).build()
  • 2、when scroll Recyclerview to PlayerView item :
holder.playView.player = mPlayer
val firstLocalMediaItem = MediaItem.fromUri(url)
mPlayer?.run {
      clearMediaItems() //  only one video to play
      repeatMode = Player.REPEAT_MODE_ALL
      addMediaItem(firstLocalMediaItem)
      playWhenReady = true
      prepare()
}
  • 3、when PlayerView scroll out of screen,I stop the video that is playing
if (mPlayer?.isPlaying == true) {
     mPlayer?.stop()
}
  • 4,scroll RecyclerView,two listener
// scroll RecyclerView
recyclerView.addOnScrollListener(recyclerViewScrollListener)
// scroll PlayerView is out of screen 
recyclerView.addOnChildAttachStateChangeListener(childAttachStateChangeListener)

my question:

1,My recyclerView has 2 itemType, there will be at most one PlayerView on the current screen , when I scroll to the first and second PlayerView , its playing normally , and when I scroll to the third PlayerView its just has audio , only the PlayerView is wrong in the third item, After that , one PlayerView item is normal , one PlayerView is only audio
2,What I am thinking is that the ViewHolder is being reused, but the ViewHolder for each item contains the correct content, except for the black screen when playing,There must be something wrong with my ExoPlayer operation which caused the black screen

Thank for your help

@marcbaechinger
Copy link
Contributor

Having a player in scrolling RecyclerView with a single or multiple players is an advanced topic for that we can't really provide you with support I'm afraid.

From what you report it looks like that the player is not released properly and then the number of available video decoder gets exceeded. Audio continues working with a software codec.

There is also #867 where people are discussion various options and details around the case of recycler view.

I'm closing as a duplicate of that issue. Please reopen if you think your case touches a specific library issue.

@1mean
Copy link
Author

1mean commented Mar 1, 2022

Because I just learned Exoplayer,The problem is that I don't understand api,I solved the problem in this way

holder.playView.player = null
holder.playView.player = mPlayer

I read the introduce for this method setPlayer(@Nullable Player player)

To transition a Player from targeting one view to another, it's recommended to use 
switchTargetView(Player, PlayerView, PlayerView) rather than this method. If you do wish to 
use this method directly, 
be sure to attach the player to the new view before calling setPlayer(null) to detach it from the old one. 
This ordering is significantly more efficient and may allow for more seamless transitions

Thanks

@google google locked and limited conversation to collaborators Apr 30, 2022
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

2 participants