启动一个实例后,如何暂停页面上所有正在播放的VideoJS实例? [英] How can I pause all playing VideoJS instances on page when one is started?
本文介绍了启动一个实例后,如何暂停页面上所有正在播放的VideoJS实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在想出了这个解决方案:
I came up with this solution now:
var myPlayer1 = _V_("ID1");
var myPlayer2 = _V_("ID2");
...
...
var myFunc1 = function(){
var myPlayer1 = this;
myPlayer2.pause();
myPlayer3.pause();
myPlayer4.pause();
...
};
myPlayer1.on("play", myFunc1);
var myFunc2 = function(){
var myPlayer2 = this;
myPlayer1.pause();
myPlayer3.pause();
myPlayer4.pause();
...
};
myPlayer2.on("play", myFunc2);
...
还有其他明智的方式吗?
Any other sane way to do it?
谢谢.
推荐答案
假设您使用的是jQuery,则可以尝试此解决方案.
You can try this solution, assuming you use jQuery.
您可能会尝试避免暂停当前未播放的视频.可以通过在循环中添加另一项检查来完成-在此,只要另一视频开始播放,页面上的所有视频都将暂停.
You might try to avoid pausing videos that are not currently playing. This can be done by adding another check in the loop - here all videos on the page are being paused whenever another one starts playing.
此外,也许还有更好的方法来避免使用视频ID(例如ike $(this).player或类似的名称),但这确实可以解决问题.
Also, there might be a better way to avoid the video ids ( ike $(this).player or something similar), but this does the job.
$(".video-js").each(function (videoIndex) {
var videoId = $(this).attr("id");
_V_(videoId).ready(function(){
this.on("play", function(e) {
//pause other video
$(".video-js").each(function (index) {
if (videoIndex !== index) {
this.player.pause();
}
});
});
});
});
这篇关于启动一个实例后,如何暂停页面上所有正在播放的VideoJS实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文