域名預(yù)訂/競(jìng)價(jià),好“米”不錯(cuò)過(guò)
這篇文章主要介紹了HTML5 video循環(huán)播放多個(gè)視頻的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
最近在開(kāi)發(fā)中遇到的需求是:微信掃描課件二維碼,播放其對(duì)應(yīng)的課件視頻
設(shè)計(jì)流程
1.掃描二維碼時(shí),將其視頻列表存入model中,存入第一條是為了,不在html界面重新獲取第一條視頻
model.addAttribute("playUrl", videos.get(0).getVideoUrl());
model.addAttribute("videoUrls", JsonUtils.toJson(videos));
2.返回其對(duì)應(yīng)的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="h5"
x5-video-player-fullscreen="true"
x5-video-orientation="landscape"
autoplay>
抱歉,您的瀏覽器不支持內(nèi)嵌視頻!
</video>
4.用ended 監(jiān)控視頻播放進(jìn)度
<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="h5"
x5-video-player-fullscreen="true"
x5-video-orientation="landscape"
autoplay>
抱歉,您的瀏覽器不支持內(nèi)嵌視頻!
</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>
到此這篇關(guān)于HTML5 video循環(huán)播放多個(gè)視頻的方法步驟的文章就介紹到這了,更多相關(guān)HTML5 video循環(huán)播放多視頻內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
來(lái)源:腳本之家
鏈接:https://www.jb51.net/html5/739319.html
申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!