HTML5 中 如何使用JS、 jquery 循环播放多个视频源

  1. HTML代码
java 复制代码
<body>
		<video type="video/mp4" src="" disablePictureInPicture
						                controlsList="nodownload"  autoplay="" style="width: 400px; height: 300px;" id="e_video" preload="metadata">
		     
		</video>
	</body>

2.css代码

java 复制代码
  video {
		     object-fit: fill;  
		}
  1. jquery代码
java 复制代码
<script type="text/javascript" src="js/jquery-2.1.0.min.js" ></script>
	<script>
	//静态用于演示
$(function() {	
								 var video_list  = [
									     "img/huadong1/moxing.mp4",
									    "img/huadong1/moxing.mp4"
									
									];
                                    var video_index    = 0;
                                    var video_player   = null;
 
                                    var onVideoEnded = function(){
                                        console.log("video ended");
                                        if(video_index < video_list.length - 1){
                                            video_index++;
                                        }
                                        else{
                                            video_index = 0;
                                        }
                                        console.log("playing:"+ video_list[video_index]);
                                        video_player.setAttribute("src", video_list[video_index]);
                                        video_player.play();
                                    }
                                    
                                    var onload = function(){
                                        console.log("body loaded");
                                        video_player = $("video")[0];
                                        video_player.setAttribute("src", video_list[video_index]);
                                        video_player.addEventListener('ended',onVideoEnded);
                                        video_player.play();
                                    };
 
                                    
                                   onload();

});
	</script>
相关推荐
全栈前端老曹几秒前
【前端】Hammer.js 快速上手入门教程
开发语言·前端·javascript·vue·react·移动端开发·hammer.js
亮子AI4 分钟前
【NestJS】为什么return不返回客户端?
前端·javascript·git·nestjs
Filotimo_7 分钟前
Vue3 + Element Plus 表格复选框踩坑记录
javascript·vue.js·elementui
pas13610 分钟前
32-mini-vue 更新element的children-双端对比 diff 算法
javascript·vue.js·算法
写bug的可宋19 分钟前
【Electron】解决Electron使用阿里iconfont不生效问题(react+vite)
javascript·react.js·electron
摘星编程12 小时前
React Native for OpenHarmony 实战:Linking 链接处理详解
javascript·react native·react.js
胖者是谁12 小时前
EasyPlayerPro的使用方法
前端·javascript·css
EndingCoder12 小时前
索引类型和 keyof 操作符
linux·运维·前端·javascript·ubuntu·typescript
摘星编程13 小时前
React Native for OpenHarmony 实战:ImageBackground 背景图片详解
javascript·react native·react.js
摘星编程14 小时前
React Native for OpenHarmony 实战:Alert 警告提示详解
javascript·react native·react.js