这篇文章主要介绍HTML5中video如何循环播放多个视频,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
设计流程
1.扫描二维码时,将其视频列表存入model中,存入第一条是为了,不在html界面重新获取第一条视频
model.addAttribute("playUrl", videos.get(0).getVideoUrl());
model.addAttribute("videoUrls", JsonUtils.toJson(videos));
2.返回其对应的html界面
return "client/coursePlayer.html";
3.使用video 播放视频第一条视频
<video id="videoID" controls="true"
style="object-fit:fill"
src="${playUrl}"
class="horizontal-img"
preload="metadata"
webkit-playsinline="true"
playsinline="true"
x-webkit-airplay="allow"
x5-video-player-type="h6"
x5-video-player-fullscreen="true"
x5-video-orientation="landscape"
autoplay>
抱歉,您的浏览器不支持内嵌视频!
</video>
4.用ended 监控视频播放进度
<script type="application/javascript">
videoDom.addEventListener('ended', function(event) {
if (index === length-1) {
videoDom.pause();
} else {
index += 1;
videoDom.src = videos[index].videoUrl;
videoDom.play();
}
})
</script>
html界面如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>${title}</title>
<style>
.video {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
z-index: 99;
transition: all 0.3s;
background-color: rgba(0, 0, 0, 0.5);
}
.video-content {
height: 100%;
width: 100%;
}
video {
position: initial;
}
video.horizontal-img {
width: 100%;
height: auto;
max-height: 100%;
}
</style>
</head>
<body>
<div class="video">
<div class="video-content">
<video id="videoID" controls="true"
style="object-fit:fill"
src="${playUrl}"
class="horizontal-img"
preload="metadata"
webkit-playsinline="true"
playsinline="true"
x-webkit-airplay="allow"
x5-video-player-type="h6"
x5-video-player-fullscreen="true"
x5-video-orientation="landscape"
autoplay>
抱歉,您的浏览器不支持内嵌视频!
</video>
</div>
</div>
<script type="application/javascript">
var dom = document;
var index = 0;
var videos = ${videoUrls};
var videoDom = dom.getElementById('videoID');
videoDom.play();
videoDom.addEventListener('ended', function(event) {
if (index === length-1) {
videoDom.pause();
} else {
index += 1;
videoDom.src = videos[index].videoUrl;
videoDom.play();
}
})
</script>
</body>
</html>
以上是“HTML5中video如何循环播放多个视频”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://www.jb51.net/html5/739319.html