码迷,mamicode.com
首页 > Web开发 > 详细

一个html5视频播放器

时间:2017-01-10 21:08:58      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:turn   play   idt   context   body   duration   control   pen   cli   

具有播放视频,拖拽,自定义右键菜单,上传头像的功能

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>my videoPodcast</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#box{
width: 1000px;
height: 100%;

}
#wrap{
width: 700px;
height: 900px;
margin: 0 auto;

}
ul{
list-style: none;
float: left;
clear: both;
margin-top: 4px;
}
li{
width: 150px;
height: 40px;
line-height: 40px;
font:24px/40px "微软雅黑";
cursor:pointer;
background:lightgray;
margin-top: 1px;
}
input{
display: block;
height: 40px;
width: 40px;
border-radius: 5px;
border: none;
background: darkgray;
color: #FFFFFF;
float: left;
margin-left: 2px;
}
#target{
width: 180px;
height: 100px;
border: 1px solid darkgray;
float: right;
}
#hiddenMenu{
float: right;
display: none;

}

#picContainer{
/*float: left;*/
position: absolute;
left: 330px;
top: 410px;
}
label{
display: block;
width: 180px;
height: 180px;
border-radius: 10px;
border:1px solid darkgray;
font:50px/180px "微软雅黑";
text-align: center;
/*background: url("1.jpg") center no-repeat;*/
}
input[type="file"]{
display:none;
}

</style>
</head>
<body>
<div id="box">
<div id="wrap">

<video autoplay="false" height="400px" controls="controls">
<source src="01.mp4"/>
<source src="01.ogg"/>
</video>

<input type="button" value="暂停" />
<input type="button" value="静音" />
<input type="button" value="全屏" />


<ul id="from">
<li draggable="true">01.mp4</li>
<li draggable="true">02.mp4</li>
</ul>
<!--drag session begin-->
<div id="target">
<ul id="to">

</ul>
</div>
<!--drag session end-->

<!--hidden menu begins-->
<div id="hiddenMenu">
<ul>
<li>收藏视频</li>
<li>赞赏视频</li>

</ul>
</div>
<!--hiddeb menu ends-->

<!--pic upload begins-->
<form id="picContainer">
<label for="photo">+</label>
<input type="file" id="photo"/>
<input type="button" value="提交" / id="submit">
</form>
<!--pic upload ends-->
</div>
</div>

<script type="text/javascript">
var video = document.getElementsByTagName("video")[0];
var liS = document.getElementsByTagName("li");
for(var i=0;i<liS.length;i++){


liS[i].onclick=function(){
video.src=this.innerHTML;
for(var j=0;j<liS.length;j++){
liS[j].style.background="lightgray";
}
this.style.background="darkgray";
}



}
video.oncanplay=function(){
console.log(video.duration);

}
video.ontimeupdate=function(){
console.log(video.currentTime);

}
var inp = document.getElementsByTagName("input")[0];
var mut = document.getElementsByTagName("input")[1];
var fullScreen=document.getElementsByTagName("input")[2];

inp.onclick=function(){
if(inp.value=="暂停"){
video.pause();
inp.value="播放"

inp.style.background="lightgray";

}else{
video.play();
inp.value="暂停"
// video.webkitRequestFullScreen();
inp.style.background="darkgray";
}

}
mut.onclick=function(){
if(mut.value=="静音"){
video.muted=true;
mut.value="音量"
mut.style.background="lightgray";

}else{
video.muted=false;
mut.value="静音"
mut.style.background="darkgray";

}
}
fullScreen.onclick=function(){
video.webkitRequestFullScreen();
}
//拖动功能
var target=document.getElementById("target");
var ul=document.getElementById("from");
var liS=ul.children;
var node=null;

for(var i=0;i<liS.length;i++){
liS[i].ondrag=function(){
node=this;
}
}

target.ondragover=function(e){
var event = e||window.event;
//阻止浏览器默认事件,drop才会发生
e.preventDefault();
}
target.ondrop=function(){
target.children[0].appendChild(node);
}

//自定义右键菜单
var hidderMenu=document.getElementById("hiddenMenu");

target.oncontextmenu=function(){
hidderMenu.style.display="block";

return false;
}
var box=document.getElementById("box");
box.onclick=function(){
hidderMenu.style.display="none";
}

//上传图片并显示
var fr = new FileReader();
var label = document.getElementsByTagName("label")[0]
var sub = document.getElementById("submit");
var fileInp = document.getElementById("photo");
sub.onclick=function(){
var file = fileInp.files[0];
fr.readAsDataURL(file);
fr.onloadend=function(){
label.style.background = "url("+fr.result+") center no-repeat"
}
}

</script>
</body>
</html>

 页面如下:

技术分享

 

一个html5视频播放器

标签:turn   play   idt   context   body   duration   control   pen   cli   

原文地址:http://www.cnblogs.com/rlann/p/6270725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!