toro icon indicating copy to clipboard operation
toro copied to clipboard

Video pauses when switching tabs (ViewPager)

Open jpage4500 opened this issue 7 years ago • 9 comments

Hi, I'm using the latest library (toro-extended:2.1.0) and trying to figure out a workaround for the following issue:

I've got an Activity that has a ViewPager and each of the tabs contains a RecyclerView of video items.

When the Activity starts, the video on the first tab (displayed by default) starts playing. But, if I click on the second tab the video on it doesn't play until I scroll the RecyclerView. Same thing if I change tabs back again.

I'm able to illustrate this issue fairly easily in the sample app -> basic sample 1 (see changes here: https://github.com/jpage4500/Toro/commit/017ce3b14257410a62cbe2600c23c7c1af1df193).

Oddly though, in my example it seems like videos on both tabs will play so not exactly what I'm seeing but still seems like a good test case anyway.

I'm also looking for some kind of workaround I can use to start playing videos when a tab is selected but I don't see anything obvious.. any suggestions?

  • I've tried using Toro.rest() to stop/start any videos when a tab is changed.. didn't seem to have any effect.
  • I've also tried to programmatically scroll the RecyclerView but that also didn't have any effect.

Please let me know! I'd really love to make Toro work

thanks, joe

jpage4500 avatar Dec 29 '16 17:12 jpage4500

I don't think this is a great solution but I was able to get the video in the sample app to pause and resume when switching tabs. See this change:

https://github.com/jpage4500/Toro/commit/02df05c39b33862ca095d6707061061a35ac2d06

With this change it shows the same problem I'm having now actually.. the video on the second tab won't start until you scroll the screen a little.

jpage4500 avatar Dec 30 '16 01:12 jpage4500

I have a potential fix for this issue and have done testing on the new 'tab sample' that I added to the sample app. I'm not sure if it's the best solution - but I did try several other options and it was the only one that worked.. the only downside is it required being able to access ToroScrollListener so I could 'simulate' a scroll event.

https://github.com/jpage4500/Toro/commit/e6e0222d72c50a6344bd1887f65e3b2c4a9422ac

jpage4500 avatar Dec 30 '16 19:12 jpage4500

Hi @jpage4500 , I had a temporary work for ViewPager, will bring it back for this issue soon, in few days maybe.

eneim avatar Jan 02 '17 07:01 eneim

@jpage4500 Please try to add this ToroViewPagerHelper.java as a "PageChangeListener" of your ViewPager to see if it works? Will spend some time on this if it doesn't.

P/S: Don't forget to call "ToroViewPagerHelper.remove()" right before you unregister your RecyclerView(s).

eneim avatar Jan 04 '17 09:01 eneim

sorry for the delay - I'll update my forked version with the latest changes and try ToroViewPagerHelper to see if that works.

jpage4500 avatar Jan 11 '17 15:01 jpage4500

Any update on this issue please, I got the same problem when using with Viewpager, if the video lists are not the first screen it doesn't play automatically when I swipe to it. (I'm using version 3.0.0-alpha2)

toidv avatar Jul 02 '17 10:07 toidv

For now I workaround by this way. I'm looking forward to the official way

   @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(adapter != null) {
            adapter.notifyDataSetChanged();
        }
    }

toidv avatar Jul 02 '17 10:07 toidv

@toidv having notify data set changes all the time is not so cool. I have push some code to dev-v3 branch, it comes with example for ViewPager as well (hint: the default UI is a ViewPager). I also use setUserVisibleHint, but that method can be called even before onAttach, so it requires a bit tune up to be able to use in production. Please take a look and give feedback.

dev-v3 also has some changes in the API which I suppose to push to beta-1, so if you found any issue please help feedback so I can fix it asap.

eneim avatar Jul 02 '17 13:07 eneim

i need pause a video whe switch tab.. my video still playing..

lucazin avatar Oct 30 '19 17:10 lucazin