首页 > 代码库 > js- 视频播放器

js- 视频播放器

1.

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>自制视频播放器</title>
    <style>
        *{margin: 0; padding: 0}
        #div1{width: 300px; height: 20px; background: #666; overflow: hidden;position: relative;top:10px}
        #div2{width: 30px; height: 20px;background: red; position: absolute; left: 0; top: 0;}
        #div3{width: 300px; height: 10px; background: #666; overflow: hidden;position: relative;top:20px}
        #div4{width: 30px; height: 10px;background: green; position: absolute; left: 90px; top: 0;}
    </style>
</head>
<body>
<video  id="v1">
    <source src="http://www.mamicode.com/a.mp4"/>
</video><br>
<input type="button" value="http://www.mamicode.com/播放"/>
<input type="button" value="http://www.mamicode.com/00:00:00"/>
<input type="button" value="http://www.mamicode.com/00:00:00"/>
<input type="button" value="http://www.mamicode.com/静音"/>
<input type="button" value="http://www.mamicode.com/全屏"/>
<div id="div1">
    <div id="div2"></div>
</div>
<div id="div3">
    <div id="div4"></div>
</div>
<script>
    window.onload = function(){
        var oVideo = document.getElementById(‘v1‘);
        var aInput = document.getElementsByTagName(‘input‘);
        var oDiv1 = document.getElementById(‘div1‘);
        var oDiv2 = document.getElementById(‘div2‘);//进度滑块
        var oDiv3 = document.getElementById(‘div3‘);
        var oDiv4 = document.getElementById(‘div4‘);//音量滑块
        var timer = null;

        //功能1.播放暂停
        aInput[0].onclick = function(){
            if(oVideo.paused){
                oVideo.play();
                this.value = http://www.mamicode.com/‘暂停‘;>     //获取视频总时长 00:00:00
        function changeTime(iNum){
            iNum = parseInt(iNum);
            var iH = toZero(Math.floor(iNum / 3600)); //时
            var iM = toZero(Math.floor(iNum % 3600 / 60)); //分
            var iS = toZero(Math.floor(iNum % 60)); //秒
            return iH + ":" + iM + ":" + iS;
        }
        function toZero(num){
            return num <= 9 ? ‘0‘+ num : ‘‘+ num ;
        }
    };
</script>

</body>
</html>

  

js- 视频播放器