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

bg.jpg

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);

}

};

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值