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
The system cannot hold multiple ExoPlayer
instances. It can throw an OOM Exception
. Therefore, you must release ExoPlayer
when the user does not see the item. In this case, I suggest you use the bellow method from RecyclerView.Adapter
override fun onViewDetachedFromWindow(holder: ViewHolder) {
holder.itemView.player?.stop()
holder.itemView.player?.release()
holder.itemView.player = null
super.onViewDetachedFromWindow(holder)
}
And then, in ViewHolde
r class you should check, if player == null
, you must initialize it.