小编use*_*651的帖子

视频在播放前闪烁黑色 (ExoPlayer)

我在 RecyclerView 中使用 ExoPlayer。

我现在的工作方式是:

  • 仅使用一个 ExoPlayer 实例
  • 当 RecyclerView 项目进入视图时,它会准备播放器并将 PlayerView 附加到布局
  • 当 RecyclerView 项目消失时,它会调用 setPlayer(null) 并从布局中删除 PlayerView

然而,当滚动浏览我的 RecyclerView 时,每个视频在播放前都会短暂(毫秒)闪烁黑色,如下面的视频所示:

https://user-images.githubusercontent.com/30815862/128436800-d2153174-e768-4181-9fc0-19d9dec52efb.mp4

我究竟做错了什么?我可以更改什么来防止视频播放前出现黑屏闪烁?

以下是我的 RecyclerView 适配器的相关部分:

public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private SimpleExoPlayer exoPlayer;
    private HlsMediaSource.Factory hlsMediaSourceFactory;

    public PostAdapter(Context context) {
        this.context = context;
        this.exoPlayer = new SimpleExoPlayer.Builder(context)
                .build();
        this.exoPlayer.setVideoTextureView(new TextureView(context));
        this.hlsMediaSourceFactory = new HlsMediaSource.Factory(CustomMediaSourceFactory.buildMediaSourceFactory())
                .setAllowChunklessPreparation(true); // TODO: Look into this
    }

    public class PostViewHolder extends RecyclerView.ViewHolder {
        public ConstraintLayout videoContainer;
        public ImageView videoThumbnail;
        public …
Run Code Online (Sandbox Code Playgroud)

android android-video-player exoplayer exoplayer2.x

7
推荐指数
1
解决办法
1846
查看次数