模拟播放器倒计时效果

简介:

422101-20170714213204118-1131161021.png

422101-20170714213217743-925450939.gif

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>模拟视频播放</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0">
    <link rel="stylesheet" href="../css/aui.2.0.css">
    <link rel="stylesheet" href="../css/api.css">
    <style>
        html,body{
            background-color: #000;
            width: 100%;
            height: 100%;
        }
        header img{
            position: absolute;
            width: 1.5rem;
            height: 1.5rem;
            left: 1rem;
            top: 1rem;
        }
        #play{
            width: 3rem;
            height: 3rem;
            background: url(../image/message/news_start_ico.png) no-repeat;
            background-size: 100% 100%;
            position: absolute;
            left: 50%;
            top: 50%;
            margin: -1.5rem 0 0 -1.5rem;
        }
        footer{
            width: 100%;
            height: 3rem;
            position: fixed;
            bottom: 0;
            left: 0;
        }
        #foot-left{
            width: 3rem;
            height: 3rem;
            float: left;
            position: relative;
            z-index: 100;
        }
        #foot-left img{
            width: 1.5rem;
            height: 1.5rem;
            margin: 0.75rem;
        }
        #foot-right{
            width: 100%;
            height: 3rem;
            line-height: 3rem;
            padding-left: 3rem;
            padding-right: 0.5rem;
            position: relative;
            z-index: -1;
            -webkit-overflow-scrolling: touch;
        }
        #foot-right .time-a,.time-c{
            height: 3rem;
            width: 20%;
            text-align: center;
            line-height: 3rem;
            color: #fff;
        }
        #foot-right .time-a,.time-b{
            float: left;
        }
        #foot-right .time-c{
            float: right;
        }
        #foot-right .time-b{
            width: 60%;
            height: 3rem;
        }
        #progress{
            width: 100%;
            height: 0.25rem;
            margin-top: 1.35rem;
            background-color: #69594f;
        }
        #progress .aui-progress-bar{
            background-color: #fff;
        }
    </style>
</head>
<body>
<header><img src="../image/message/video_off_ico.png" alt=""></header>
<div id="play"></div>
<footer>
    <div id="foot-left">
        <img src="../image/message/news_goon_ico.png" alt="" id="play_switch">
    </div>
    <div id="foot-right">
        <div class="time-a" id="start-time">00:00</div>
        <div class="time-b">
            <div class="aui-progress aui-progress-xxs" id="progress">
                <div class="aui-progress-bar" id="slider"></div>
            </div>
        </div>
        <div class="time-c" id="total-time">00:00</div>
    </div>
</footer>

<script type="text/javascript" src="../script/jquery.min.js"></script>

<script>

    !function (d) {
        var runs = false;

        var video_time = 5;
        if (video_time >= 10) {
            document.querySelector('#total-time').innerText = '00:'+video_time;
        } else {
            document.querySelector('#total-time').innerText = '00:0'+video_time;
        }
        d.querySelector('#play').onclick=function () {
            runs = !runs;
            run('slider',video_time);
        }

        d.querySelector('#play_switch').onclick=function () {
            runs = !runs;
            run('slider',video_time);
        }


        var settime,playtime=0;
        function run(id,time) {
            var i = 0,start;
            if(runs){
                dealswitch('start');
                settime = setInterval(function () {
                        start = parseInt((playtime+1)*time/100);
                        if (start >= 10) {
                            document.querySelector('#start-time').innerText = '00:'+start;
                        } else {
                            document.querySelector('#start-time').innerText = '00:0'+start;
                        }

                        if(playtime != 0){
                            document.querySelector('#'+id).style.width = (playtime++)+'%';
                        } else {
                            document.querySelector('#'+id).style.width = (i++)+'%';
                            playtime = i;
                        }
                        if (playtime == 100) {
                            playtime = 0;
                            runs =  !runs;
                            dealswitch('stop');
                            clearInterval(settime);
                        }
                    },time*10);
            }else{
                clearInterval(settime);
                dealswitch('stop');
            }

        }

        function dealswitch(operation) {
            if (operation == 'stop') {
                $("#play").show();
                $("#play_switch").attr('src','../image/message/news_goon_ico.png');
            } else {
                $("#play").hide();
                $("#play_switch").attr('src','../image/message/news_stop_ico.png');
            }
        }
    }(document);

</script>

</body>
</html>

值得好好参谋。



本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/7172358.html,如需转载请自行联系原作者

相关文章
|
11月前
|
小程序
UniApp video 使用(自定义进度条,及微信无法暂停播放设置进度问题)
UniApp video 使用(自定义进度条,及微信无法暂停播放设置进度问题)
1004 0
|
19天前
|
存储 Android开发
安卓app,MediaPlayer播放本地音频 | 按钮控制播放和停止
在Jetpack Compose中,不直接操作原生Android组件如`Button`和`MediaPlayer`,而是使用Compose UI构建器定义界面并结合ViewModel管理音频播放逻辑。以下示例展示如何播放本地音频并用按钮控制播放/停止:创建一个`AudioPlayerViewModel`管理`MediaPlayer`实例和播放状态,然后在Compose UI中使用`Button`根据`isPlaying`状态控制播放。记得在`MainActivity`设置Compose UI,并处理相关依赖和权限。
|
19天前
|
API Android开发 Kotlin
kotlin 音频播放,多音轨同时播放,音频播放期间,可以随时设置播放速度
在Android中,`SoundPool` 适合播放短音频但不支持直接改变播放速度。若需调整播放速度,可使用 `AudioTrack` 或 `MediaPlayer`。以下是一个使用 `MediaPlayer` 实现多音轨播放并调整播放速度的简单Kotlin代码示例,特别注意,`setPlaybackParams` 方法在API 23及以上版本才能调整播放速度。别忘了在不再使用时释放 `MediaPlayer` 资源以防止内存泄漏。
|
2月前
文字转语音后的音频结束以后,再播放一段时间的背景音乐。什么方案能实现
【2月更文挑战第13天】文字转语音后的音频结束以后,再播放一段时间的背景音乐。什么方案能实现
33 2
|
2月前
uniapp制作录音播放功能
uniapp制作录音播放功能
96 0
|
2月前
|
计算机视觉 Python
OpenCV实现视频的暂停播放和继续播放功能实战(附Python源码)
OpenCV实现视频的暂停播放和继续播放功能实战(附Python源码)
173 0
|
11月前
|
前端开发 JavaScript
uniapp 录音和播放功能
uniapp 录音和播放功能
271 0
倒计时功能制作
今天制作一个商城项目距离抢购还剩多长时间的一个小功能 首先要知道这个倒计时是不断的变化的,所以需要用到定时器来自动变化(setInterval),有三个标签存放时分秒,再利用innerHTML将计算出来的时间放入三个标签内,第一次执行也是间隔毫秒数,因此刷新页面会有空白,我们最好采取封装函数的方式,这样可以先调用一次这个函数,防止刚开始刷新页面有空白问题。
|
12月前
|
存储 移动开发 小程序
小程序:播放视频
小程序:播放视频
314 0
|
小程序 API UED
微信小程序|音频音乐播放控制
微信小程序|音频音乐播放控制
305 0