Вопрос

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?
Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top