pause JW player?

偶尔善良 提交于 2019-12-13 14:19:39

问题


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?

回答1:


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



来源:https://stackoverflow.com/questions/22091761/pause-jw-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!