最近在開發(fā)中遇到的需求是:微信掃描課件二維碼,播放其對應(yīng)的課件視頻
設(shè)計(jì)流程
1.掃描二維碼時(shí),將其視頻列表存入model中,存入第一條是為了,不在html界面重新獲取第一條視頻
model.addAttribute("playUrl", videos.get(0).getVideoUrl()); model.addAttribute("videoUrls", JsonUtils.toJson(videos));
2.返回其對應(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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
標(biāo)簽:新疆 遼源 青島 永州 漯河 棗莊 西藏 池州
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HTML5 video循環(huán)播放多個(gè)視頻的方法步驟》,本文關(guān)鍵詞 HTML5,video,循環(huán),播放,多個(gè),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。