基于HTML5自定义媒体播放器

简要说明

显示播放时间、可操控进度条,播放视频是通过拖拽媒体文件到播放器中即可播放。
注:上一曲、下一曲未实现。

素材

这里写图片描述 这里写图片描述 这里写图片描述 这里写图片描述
这里写图片描述

效果图

这里写图片描述
这里写图片描述
这里写图片描述

style.css文件

.mediaplayer {
    height: 350px;
    width: 534px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -267px;
    margin-top: -175px;
    box-shadow: 0px 0px 30px #555555;
    border: 1px solid rgb(153, 153, 153);
}

.video {
    width: 100%;
    text-align: center;
    background: rgba(0, 0, 0, 0.6);
    padding: 0;
}

.process {
    position: absolute;
    height: 8px;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.4);
    margin-top: -13px;
    z-index: 2;
    border-radius: 10px;
    display: none;
}

.process span {
    position: absolute;
    height: 100%;
}

.process #process-value {
    border-radius: 10px;
    width: 0px;
    box-shadow: 0px 0px 5px #555;
    background-color: #4d4d4d;
}

.process #process-sel {
    display: none;
    width: 1px;
    background-color: #000;
}

.tooltip {
    position: absolute;
    z-index: 9;
    display: none;
}

.tooltip span {
    position: absolute;
    color: #fff;
    top: -45px;
    font-size: 10px;
    line-height: 1.4em;
    border: 1px solid #CCCCCC;
    border-radius: 2px;
    padding: 2px 3px;
    background-color: #8A8A8A;
}

.tooltip span:after,
span:before {
    border: solid transparent;
    content: ' ';
    width: 0px;
    height: 0px;
    position: absolute;
    top: 20px;
}

.tooltip span:after {
    border-width: 5px;
    border-top-color: #8A8A8A;
    left: 13px;
}

.tooltip span:before {
    border-width: 6px;
    border-top-color: #FFFFFF;
    left: 12px;
}

.controls {
    position: absolute;
    text-align: center;
    bottom: 0px;
    width: 100%;
    height: 50px;
    background: #d4d4d4;
}

.controls button {
    height: 100%;
    width: 10%;
    border: none;
    background-color: #00000000;
    background-repeat: no-repeat;
    background-position: center;
    outline: none;
}

.controls #video-btn-pre {
    background-image: url(../img/pre.png);
}

.controls #video-btn-pp {
    background-image: url(../img/play.png);
}

.controls #video-btn-next {
    background-image: url(../img/next.png);
}

.controls span {
    color: #555;
    position: absolute;
    top: 20px;
    text-shadow: 1px 1px 1px #AAAAAA;
}

.controls #curtime {
    left: 15px;
}

.controls #duration {
    right: 15px;
}


EventUtil.js文件

var EventUtil = {
    addHandler: function(element, type, handler){
        if (element.addEventListener){
            element.addEventListener(type, handler, false);
        } else if (element.attachEvent){
            element.attachEvent("on" + type, handler);
        } else {
            element["on" + type] = handler;
        }
    },
    preventDefault: function(event){
        if (event.preventDefault){
            event.preventDefault();
        } else {
            event.returnValue = false;
        }
    }
};


DIYVideoPlayer.html文件

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>DIY Video Player</title>
        <script type="text/javascript" src="js/EventUtil.js"></script>
        <link rel="stylesheet" href="css/style.css" />
        <script type="text/javascript" src="js/scripts.js"></script>
    </head>
    <body>
        <div class="mediaplayer">
            <div class="video">
                <video id="player" width="534" height="300" poster="img/poster.png">Video player not available.</video>
            </div>
            <div class="process" id="process">
                <span id="process-value"></span>
                <span id="process-sel"></span>
            </div>
            <div class="tooltip" id="tooltip">
                <span id="tooltip-value">00:00</span>
            </div>
            <div class="controls">
                <button id="video-btn-pre" />
                <button id="video-btn-pp" />
                <button id="video-btn-next" />
                <span id="curtime">00:00</span>
                <span id="duration">00:00</span>
            </div>
        </div>
    </body>
</html>

结束语

这是我在学习JavaScript时,利用所学知识综合运用所写,若有错误误导大家,请大家留言沟通,谢谢。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值