toro icon indicating copy to clipboard operation
toro copied to clipboard

How to disable auto play

Open j3p0n opened this issue 8 years ago • 13 comments

How to disable auto play, but user can still play/pause manualy? or disable auto play when network is on GPRS, and enabl auto play when on WIFI or 4G?

j3p0n avatar Jun 06 '16 06:06 j3p0n

@j3p0n You can have your own Strategy which does nothing, for example a lazyStrategy. So when you want to disable auto playback, just call Toro.setStrategy(lazyStrategy). See how I implement Toro.rest(boolean) for more information.

eneim avatar Jun 06 '16 06:06 eneim

I created own lazyStrategy and called Toro.setStrategy(lazyStrategy) playback was disabled, but how to pause/play video when user clicks on video?. In this case adapter.getPlayer() returns null.

j-a-s-o-n avatar Oct 11 '16 16:10 j-a-s-o-n

This intention of this library is to solely autoplay videos one at a time which it does nicely.

Quickfix - for temporarily disabling autoplay, inside the viewholder that extends ToroPlayer, there a method play(). Just add playerView.getPlayer().setPlayWhenReady(false) after the exoplayerViewHelper.play().

foodied avatar Jun 06 '18 05:06 foodied

@foodied You can always return a 'conditional false' from wantsToPlay (assuming that you are using Toro 3.x) ;). It will disable the auto play for a certain ToroPlayer. To disable that for all players, you can use PlayerSelector.NONE for the Container.

eneim avatar Jun 06 '18 05:06 eneim

I did set the container.setPlayerSelector(PlayerSelector.NONE) but it seems that video is not loaded as it comes to the center. It just shows the shutter view. I am using the 3.4.2 version of the lib.

foodied avatar Jun 06 '18 06:06 foodied

@foodied Yep, it will not start loading (SimpleExoPlayer will not call 'prepare') if you don't have it starts. You can put a thumbnail view on top to hide the black screen though ... What is the behaviour you demand?

eneim avatar Jun 06 '18 06:06 eneim

Well, I guess immediate playback without any buffering when I click on play.

foodied avatar Jun 06 '18 06:06 foodied

@foodied "immediate playback without any buffering" you mean that [1] Do not start the playback automatically, but [2] When click to play button (so User has a chance to manually start the playback), it will start right away (which is equal to that the MediaSource is already ready for playback)?

This can be archive by create your own version of "ExoPlayerViewHelper" (copy/paste should work), and instead of calling playable.prepare(false) you can call playable.prepare(true). This way, it will start loading the source as soon as possible.

See this line for reference.

eneim avatar Jun 06 '18 06:06 eneim

Yes, I guess that would work as well along with PlayerSelector.NONE. Thanks! Btw do you think of any side-effects of the line that I suggested?

foodied avatar Jun 06 '18 06:06 foodied

@foodied Please try that and tell me if it doesn't work well for you. I disable the loading by default to save the resource and improve scrolling performance. It should be on-demand, I will consider to have an option to turn it on-off in next release.

eneim avatar Jun 06 '18 06:06 eneim

EventListeners inside Playable is not public. The default constructor EventListeners() has been made package-private.

foodied avatar Jun 06 '18 06:06 foodied

@foodied which version of Java you are compiling with? Java 7+ will allow EventListeners to be accessible by default (it is a class inside a public interface).

eneim avatar Jun 06 '18 06:06 eneim

@eneim Should the container.setPlayerSelector(PlayerSelector.NONE) be called before the container is populated? Looks like setPlayerSelecter doesn't work when called after the container is already populated and scrolled.

yjin avatar Feb 07 '22 08:02 yjin