Midhilaj
Midhilaj

Reputation: 4987

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

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?

Upvotes: 2

Views: 1202

Answers (2)

aminography
aminography

Reputation: 22832

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

Upvotes: 1

Pratik Butani
Pratik Butani

Reputation: 62419

Here I found some links for you :

You can understand the concept after seeing these links.

For your question I just google that play pause video in recylcerview android and I hope next time you will do same things as I do.

Note: Everything is not possible to write in comment so I wrote as an answer.

Thank you.

Upvotes: 0

Related Questions