我希望在浏览器中启用循环的HTML5视频与JavaScript不支持循环标记(ff)。有没有人知道访问视频播放结束并将播放恢复为零的可行性?
发布于 2010-08-11 12:27:18
您可以检测是否支持loop属性,并将其设置为true。
对于不支持它的浏览器,您可以简单地绑定ended媒体事件,然后重新开始:
var myVideo = document.getElementById('videoId');
if (typeof myVideo.loop == 'boolean') { // loop supported
myVideo.loop = true;
} else { // loop property not supported
myVideo.addEventListener('ended', function () {
this.currentTime = 0;
this.play();
}, false);
}
//...
myVideo.play();发布于 2017-11-25 14:50:04
您可以简单地通过loop="false"循环打开或关闭视频,以停止自动视频重复播放。
<iframe style="position: absolute; top: 0; left: 0;"
src="http://video/name.mp4" width="100%" height="100%" frameborder="0" webkitallowfullscreen loop="true" controls="false" mozallowfullscreen allowfullscreen></iframe>此loop="true"将启用视频播放器循环。
发布于 2017-07-31 21:12:26
<div>Iteration: <span id="iteration"></span></div>
<video id="video-background" autoplay="" muted="" controls>
<source src="https://res.sdfdsf.mp4" type="video/mp4">
</video>
var iterations = 1;
document.getElementById('iteration').innerText = iterations;
var myVideo = document.getElementById('video-background');
myVideo.addEventListener('ended', function () {
alert('end');
if (iterations < 2) {
this.currentTime = 0;
this.play();
iterations ++;
document.getElementById('iteration').innerText = iterations;
}
}, false);
// Please note that loop attribute should not be there in video element in order for the 'ended' event to work in ie and firefoxhttps://stackoverflow.com/questions/3455229
复制相似问题