html5的vedio循环轮播视频和图片,

6 篇文章 1 订阅
<img id="imgView" src="images/bg.jpg" class="thumbnail" />
<video id="videoView" src=""  autoplay="autoplay" controls  volume="true" muted="muted" ></video>
var notices = null;
var imgsAndVideos = null;
var words = null;
$(function () {
	// 查询屏幕数据
	let dataUrl = dataPath + "/content/screen";

	$.ajax({
		type: "GET",
		contentType: "application/x-www-form-urlencoded;charset=UTF-8",
		url: dataUrl,
		data: 'json',
		success: function (result) {
			console.log(result.data);
			startInterval(result.data);
		},
		//请求失败,包含具体的错误信息
		error: function (e) {
			console.log(e.status);
			console.log(e.responseText);
			console.log("查询搜索热度出错了");
		}
	});


});
function startInterval(data) {
	notices = data.notices;
	words = data.words;
	imgsAndVideos = data.videosAndPictures;

	$('#notice').html(notices[0]);
	$('#words').html(words[0]);
	handleImgVideoUrl(imgsAndVideos);
}
function handleImgVideoUrl(imgsAndVideos) {
		// 设置图片和视频播放
	// let iavSize = imgsAndVideos.length;
	var vList=[];
	// var vList = ['0:https://www.runoob.com/try/demo_source/movie.mp4','1:http://www.runoo.png']; // 播放列表
	for (let index = 0; index < imgsAndVideos.length; index++) {
		vList.push(imgsAndVideos[index]);
	}

	var myvideo = document.getElementById("videoView");
	var vLen = vList.length;
	if (vList[curr].indexOf('0:') >= 0) {
			$("#imgView").hide();
			$("#videoView").show();
			// myvideo.src = vList[curr];
			let url = vList[curr].replace('0:', '');
			$('#videoView').attr('src', url);
			// myvideo.muted=true;
			myvideo.load();
			myvideo.play();
			// curr++;
	}else{
		let url = vList[curr].replace('1:', '');
		$("#videoView").hide();
		$("#imgView").show();
		$("#imgView").attr("src", url);
		curr++;
		if (curr >= vLen) {
			curr = 0; //重新循环播放
		}
		// console.log("当前图片地址:1" );
		setTimeout(function () {
			console.log("当前图片地址:2" );
			handleImgVideoUrl(imgsAndVideos);
		}, 3000);
	}
	
	//视频播放完执行的方法
	myvideo.onended = function () {
		if (vList[curr].indexOf('0:') >= 0) {
			$("#imgView").hide();
			$("#videoView").show();
			// myvideo.src = vList[curr];
			let url = vList[curr].replace('0:', '');
			$('#videoView').attr('src', url);
			// myvideo.muted=true;
			myvideo.load();
			myvideo.play();
			curr++;
			if (curr >= vLen) {
				curr = 0; //重新循环播放
			}
			handleImgVideoUrl(imgsAndVideos);
		} else {
			
				
				// 图片
				// let imgUrl = prefixUrl.substring(2);
				let url = vList[curr].replace('1:', '');
				$("#videoView").hide();
				$("#imgView").show();
				$("#imgView").attr("src", url);
				//$('#videoView').get(0).pause();
				console.log("当前图片地址:" + url);
				curr++;
				if (curr >= vLen) {
					curr = 0; //重新循环播放
				}
				setTimeout(function () {
					handleImgVideoUrl(imgsAndVideos);
				}, 3000);

		}

	};
}

 

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xingchen678

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值