我尝试设置video1 = false,当percentage = 100时,更改video1 = true,并使用if-else条件检查video1的值以隐藏或显示进度条。但是当percentage = 100时,为什么不返回video1 = true。**我想在每个视频中保留一个单独的变量。
function light(Cvideo) {
var player = videojs("videoP");
var video1 = false;
var video2 = false;
var video;
if (Cvideo == 1) {
document.getElementById("nameV").innerHTML =
"1";
video = "video/1.mp4";
if ((video1 === false)) {
player.controlBar.progressControl.hide();
player.on("timeupdate", function () {
var percentage = (player.currentTime() / player.duration()) * 100;
document.getElementById("percentage").innerHTML =
Math.round(percentage) + "%";
if (percentage === 100) {
video1 = true;
}
});
} else if ((video1 === true)) {
player.controlBar.progressControl.show();
}
} else if (Cvideo == 2) {
document.getElementById("nameV").innerHTML = "2";
video = "video/2.mp4";
if ((video2 === false)) {
player.controlBar.progressControl.hide();
player.on("timeupdate", function () {
var percentage = (player.currentTime() / player.duration()) * 100;
document.getElementById("percentage").innerHTML =
Math.round(percentage) + "%";
if (percentage === 100) {
video2 = true;
}
});
} else if ((video2 === true)) {
player.controlBar.progressControl.show();
}
}
player.src({ type: "video/mp4", src: video });
player.play();
}
<video id="videoP" class=" video-js vjs-fluid" controls data-setup='{}'>
<source src="video/1.mp4" type="video/mp4">
</video>
<p id="percentage">0</p>
<a href="#" class="nav-link text-dark ms-3" id="videoLink1"onclick="light(1)">1</a>
<a href="#" class="nav-link text-dark ms-3" id="videoLink2"onclick="light(2)">2</a>
2条答案
按热度按时间wsewodh21#
你的代码不工作,因为它抛出这个错误-
Uncaught ReferenceError: videojs is not defined
。我包括了videojs包以及相关的css在更新fiddle。尝试下面的代码。这确实抛出了一个错误-
No compatible source was found for this media
。但是代码可以工作。这个错误可能是由于videojs中缺少一些配置。我还没有调试这个,但是这个应该可以解决你的问题jk9hmnmh2#
我已经解决了我的问题。这是我需要的代码