HTML5视频(⾃定义视频播放器源码)video对象
兼容情况:
safari浏览器不⽀持webm格式
Chrome浏览器⽀持webm格式
ie8以及以下不⽀持video标签 , ie9⽀持video标签 ,但是⽀持mp4格式的
Firefox(⽕狐浏览器)⽀持ogv格式的视频
兼容性写法
<video controls>
<source src="data/demo.ovg">
<source src="data/demo.mp4">
<source src="data/demo.webm">
您的浏览器不⽀持,请升级您的浏览器
</video>
video 标签 width height autoplay muted
poster带有预览图(海报图⽚)的视频播放器
<video src='data/demo.mp4' muted controls autoplay height='400' width="200" poster='data/poster.jpg'></video>
选中video标签
var VideoNode = ElementById('myVideo');
src控制视频的来源
VideoNode.src = 'v';
⼿动设置控件 controls
设置视频⾳量
VideoNode.volume = 0.5;
currentTime当前播放时间
快进效果
VideoNode.currentTime = VideoNode.currentTime + 3;
};
暂停 pause()
VideoNode.pause();
};
播放play()
VideoNode.play();
};
load 刷新播放器的事件
VideoNode.src = 'data/demo.mp4';
VideoNode.load();
};
canplay 视频已经加载好 可以开始播放了
VideoNode.addEventListener('canplay',function(){
console.log('视频已经加载好可以开始播放了');
});
requestFullscreen 让video标签变成全屏
VideoNode.webkitRequestFullscreen();
if(VideoNode.webkitRequestFullscreen){
VideoNode.webkitRequestFullscreen();
}
else RequestFullScreen){
}
};
volumechange 当⾳量更改时
console.log('volumechange');
};
声⾳随机更改
VideoNode.volume = Math.random();
};
seeking 当⽤户开始拖动进度条时 就会触发的事件
var seekingNum = 0;
console.log('');
seekingNum++;
seeking.innerHTML = seekingNum;
};
seeked 当⽤户对视频的进度条并且已经完成操作时会触发的事件
var seekedNum = 0;
console.log('');
seekedNum++;
seeked.innerHTML = seekedNum;
};
timeupdate监听视频播放的状态
VideoNode.addEventListener('timeupdate',function(){
// 总时长,以分钟:秒的形式显⽰
let allTime = parseInt(VideoNode.duration/60)+':'+parseInt(VideoNode.duration%60);
// 当前时间,以分钟:秒的形式显⽰
let nowTime = parseInt(VideoNode.currentTime/60)+':'+parseInt(VideoNode.currentTime%60); timeNode.innerHTML = nowTime+'/'+allTime;
})
readyState 视频的准备信息
console.adyState);
setTimeout(function(){
console.adyState);
},500);
playbackRate 查看或设置视频的⼀个播放速度
console.log(VideoNode.playbackRate)
Rate设置倍速
//Rate设置0.5倍速
RateNode.children[0].onclick = function(){
VideoNode.playbackRate = 0.5;
};
//Rate设置1倍速
RateNode.children[1].onclick = function(){
VideoNode.playbackRate = 1;
};
//Rate设置2倍速
RateNode.children[2].onclick = function(){
VideoNode.playbackRate = 2;
};
loop的设置
if(VideoNode.loop == false){
this.innerHTML = '循环';
VideoNode.loop = true;
}
else{
this.innerHTML = '不循环';
VideoNode.loop = false;
}
};
src返回的数据
console.log('src='+VideoNode.src);
currentSrc返回的数据
console.log('currentSrc='+VideoNode.currentSrc);
监听ended事件
VideoNode.addEventListener('ended',function(){
console.log('视频播放结束了');
VideoNode.play();
html导航源码})
查看视频的⽹络状态
console.log(VideoNodeworkState)
⼿动设置控件 controls
⼿动设置静⾳ muted
VideoNode.muted = true;
⾃定义视频播放器
放图
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{margin: 0;padding: 0;list-style: none;}
.outerNode{width: 540px;height: 332px;position: absolute;left: 50%;top: 50%;margin: -166px 0 0 -270px;box-shadow: 0 0 4px #5b606d;} .outerNode .videoNode{
width: 540px;height: 305px;float: left;
background: black;
}
.outerNode .controlsNode{
width: 540px;height: 27px;float: left;background: url(images/ctrs_bg.gif) repeat-x;
}
.outerNode .controlsNode .playNode{
float: left;width: 15px;height: 17px;margin: 6px 0 0 14px;
background: url(images/playNode.png) no-repeat;cursor: pointer;
}
.outerNode .controlsNode .pauseNode{
float: left;width: 15px;height: 17px;margin: 6px 0 0 14px;
background: url(images/pause.png) no-repeat;cursor: pointer;
}
.outerNode .controlsNode .loadNode{width: 267px;height: 10px;margin: 9px 0 0 14px;float: left;background: url(images/load_bg.png) repeat-x;position: relative;}
.outerNode .controlsNode .loadNode .lineNode{
width: 0%;height: 7px;position: absolute;left: 0;top: 1px;
background: url(images/line_bg.png) repeat-x;
}
.outerNode .controlsNode .loadNode .lineNode .lineRight{
width: 2px;height: 100%;position: absolute;right: 0;top: 0;
background: url(images/line_r_bg.png) no-repeat;
}
.outerNode .controlsNode .loadNode .loadLeft{
height: 100%;width:3px ;position: absolute;left: 0;top: 0;
background: url(images/left_bg.png) no-repeat;z-index: 4;
}
.outerNode .controlsNode .loadNode .loadRight{
height: 100%;width:3px ;position: absolute;right: 0;top: 0;
background: url(images/right_bg.png) no-repeat;
}
.outerNode .controlsNode .loadNode .crlNode{width: 17px;height: 17px;background: url(images/crl_bg.png);position: absolute;left: -8.5px;top: -
3.5px;cursor: pointer;z-index: 5;}
.outerNode .controlsNode .timeNode{
float: left;width: 75px;height: 10px;margin: 9px 0 0 9px;
}
.outerNode .controlsNode .timeNode span{font-size:10px;float: left;line-height: 10px;color: white; }
.outerNode .controlsNode .volumeNode{
width: 17px;height: 16px;float: left;margin: 5px 0 0 6px;
background: url(images/volume_bg.png);
}
.outerNode .controlsNode .volumeLine{
height: 8px;width: 61px;float: left;margin: 10px 0 0 4px;
background: url(images/volumeLine_bg.png) repeat-x;position: relative;
}
.outerNode .controlsNode .volumeLine .v_left{
width: 3px;height:100%;position: absolute;left: 0;top: 0;background: url(images/v_left.png) no-repeat;
}
.outerNode .controlsNode .volumeLine .v_right{
width: 3px;height:100%;position: absolute;right: 0;top: 0;background: url(images/v_right.png) no-repeat;
}
.outerNode .controlsNode .volumeLine .v_DragNode{width: 15px;height: 13px;position: absolute;left: 58.5px;top: -3.5px;background:
url(images/vo_d.png) no-repeat;cursor: pointer;}
.outerNode .controlsNode .fullNode{
width:15px;height:17px;float: left;margin: 6px 0 0 35px;
background: url(images/full_bg.png) no-repeat;cursor: pointer;
transition: 0.7s;
}
.outerNode .controlsNode .fullNode:hover{
background: url(images/full_hover_bg.png) no-repeat;
}
</style>
</head>
<body>
<!-- 最外层的元素 -->
<div class='outerNode'>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论