使用全局变量控制视频播放列表
问题描述:
我有一段时间播放视频的视频播放列表。 我需要的播放列表继续,直到达到名为环视频和循环视频,直到全局变量lvl1_win或lvl2_loose之一(从不同的脚本)转1. 根据结果,播放不同的播放列表,playlist_lvl2或playlist_lvl1_gameover 这是我正在使用的播放列表。它只是循环的视频可以在一段时间后:使用全局变量控制视频播放列表
var activeloop;
var myvid = document.getElementById('intro_lvl1');
myvid.addEventListener('ended', function (e)
{
var activesource = document.querySelector("#intro_lvl1 source.active");
var nextsource = document.querySelector("#intro_lvl1 source.active +
source") ||
document.querySelector("#intro_lvl1 source:first-child");
//for the video with the name "loop" in it.
var loopsource = document.querySelector("#intro_lvl1 source.loop");
activesource.className = "";
nextsource.className = "active";
myvid.src = nextsource.src;
myvid.play();
});
任何人可以给我就如何落实这几个建议?
答
您可以使用RegExp.prototype.test()
检查是否.src
包含"loop"
,设置.loop
到true
if (/loop/.test(nextsource.src)) {
// perform logic here
if (myvid.loop != true) {
myvid.loop = true
};
if (lvl1_win == 1 || lvl2_loose == 1) {
// do other stuff
}
}
答
谢谢您的回答! 我得到了它与以下工作:
var lvl1_win;
var lvl1_loose;
var myvid = document.getElementById('intro_lvl1');
myvid.addEventListener('ended', function (e) {
var activesource = document.querySelector("#intro_lvl1 source.active");
var nextsource = document.querySelector("#intro_lvl1 source.active +
source") || document.querySelector("#intro_lvl1 source:first-child");
if (/loop/.test(nextsource.src)) {
if (myvid.loop != true) {
myvid.loop = true;
};
if (lvl1_win == 1) {
alert("Won level 1");
}
if (lvl1_loose == 1) {
alert("Gameover level 1");
}
} else {
activesource.className = "";
nextsource.className = "active";
myvid.src = nextsource.src;
myvid.play();
}
});
但是,我不能添加赢得或同一源失去了特定的视频,否则会弄乱播放列表。 或者是否有可能播放下一个视频类宽松如果失去反之亦然? 我的意思:
如果(lvl1_loose == 1)
fixet语法{ 播放下一带班GAMEOVER 然后播放暂停视频最后一帧(结束循环) 视频} ,使它更清晰和固定的布局 –