0

I have an ListView with 5 different layouts, one of them is an VideoView. The whole ListView ist like an Circular loop with those 5 items like explained here.

Now i want the VideoView to stop playing when the ListView starts Scrolling. When im thinking right i have to get the right position of the VideoView that is Displayed?

Thanks (Im new to Programming!)

Community
  • 1
  • 1
Daniel Storch
  • 327
  • 1
  • 3
  • 15

1 Answers1

0

I did something very similar recently, but with WebViews instead of VideoViews.

Since you already have a custom adapter for the list, it is probably easiest to also implement the pausing of the the VideoView there:

1.) Have your adapter keep a reference to the VideoView (or all VideoViews if there are multiple). Since the layouts are created in getView() this is where you'll have to get the reference.

2.) Give your adapter a method like pausePlayback() that in turn pauses all VideoViews.

3.) Likewise, you'll need a resumePlayback() method.

4.) Where ever you have a reference to your ListView (Activity or Fragment), use myListView.setOnScrollListener() to register a callback that's called everytime your ListView is scrolled.

In the listener, depending on when exactly the playback should paused/resumed use either

onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)

or

onScrollStateChanged(AbsListView view, int scrollState)

to check if the VideoView should be paused or not and call your adapter's methods accordingly.

david.mihola
  • 12,062
  • 8
  • 49
  • 73