Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pause JW player?

I have three tabs.

Each tab having two videos in slider. The problem is when I switch any tab or click any single video,all other should pause.

I can collect all the ids and then loop over to use stop().But is there any other method that is much more cleaner and simpler.?

jwplayer('video_pub').stop(); //for 1 video..how can i do for all videos?
like image 882
HIRA THAKUR Avatar asked Feb 14 '23 15:02

HIRA THAKUR


1 Answers

Instead of using jwplayer().stop(), you can use jwplayer().pause()

for this, I mostly prefer jwplayer().play(false).

Source : Jwplayer API

LOGIC

just get the parent video wrapper which have all tab (since each tab has two video)... find jwplayer whiich is currently being played and stop all other players.

pauseMedia : function(playingMediaId) {
        $('#parent_video_wrapper').find('.jwplayer, object').each(function(){
            currentMediaId =$(this).attr('id');
            if( jwplayer(this).getState() == "PLAYING" || jwplayer(this).getState() == "BUFFERING" ) {
                if(currentMediaId != playingMediaId){
                    jwplayer(this).play(false);
                }
            }
        });
}

now you can either use above function as pauseMedia() or pauseMedia(mediaId), Both will work

In video Setup if you use it like this

jwplayer("video_"+videoId).setup({

events : {
onPlay : function (callback){
        var playingVideoId = 'video_'+videoId;
        pauseMedia(playingVideoId); 
       //pausing other simulatenously playing video in a tab

}
}
});

I think above code might do the trick, just give it a try

like image 186
Hitesh Avatar answered Feb 16 '23 06:02

Hitesh