Release ExoPlayer in RecyclerView

后端 未结 3 1695
被撕碎了的回忆
被撕碎了的回忆 2021-02-10 01:51

I am implementing the ExoPlayer in a RecyclerView. But while scrolling the Video stops, but not the audio.

How can I release the ExoPlayer in the RecyclerView? Or how c

3条回答
  •  死守一世寂寞
    2021-02-10 02:37

    I think that it would be cleanest to release the player when its view is recycled.

    Adapter Class:

    @Override
    public void onViewRecycled(@NonNull ViewHolder holder) {
        int position = holder.getAdapterPosition();
        if (mDataset.get(position) != null) {
            mDataset.get(position).getPlayer().release();
        }
        super.onViewRecycled(holder);
    }
    

提交回复
热议问题