HIRA THAKUR
HIRA THAKUR

Reputation: 17757

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?

Upvotes: 4

Views: 8685

Answers (1)

Hitesh
Hitesh

Reputation: 4288

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

Upvotes: 9

Related Questions