when onBindViewHolder called play video and if not stop video in recyclerview

Viewed 805

I need to play video when onBindViewHolder() is called and then if the item is scrolled down or top, I need to stop that video. How to do it in RecyclerView's adapter?

2 Answers

You can override onViewAttachedToWindow(VH holder) and onViewDetachedFromWindow(VH holder) methods in your adapter. Then start and stop the video in their body. As documentation said:

onViewAttachedToWindow is called when a view created by this adapter has been attached to a window.

onViewDetachedFromWindow is called when a view created by this adapter has been detached from its window.

Visual Result:

enter image description here

Related