HTML5入门6---视频播放按钮

本文介绍了一个基于HTML和JavaScript实现的视频播放器控制条,包括播放、暂停、停止等功能,并支持快进、慢放及正常速度播放。通过进度条显示当前播放位置,同时提供了简单的状态提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>第四个页面</title>
        <style>
            h1{
                font-size: x-large;
                margin: 6px 0px;
            }
            video{
                border:double 8px lightgray;
            }
            .videoContainer{
                max-width: 450px;
            }
            #postionBar{
                height: 30px;
                color:black;
                font-weight: bold;
                background: steelblue;
                text-align: center;
            }
            #postionBar span{
                display: inline-block;
                width: 450px;
                margin-bottom: 5px;
            }
            #durationBar{
                border: solid 1px;
                width: 450px;
                margin-bottom: 5px;
            }
        </style>
        <script type="text/javascript">
            var video;
            var display;
            window.onload = function(){
                video = document.getElementById("videoPlayer");
                display = document.getElementById("displayStatus");
                video.onplaying = function(){
                    display.innerHTML = "Playing......";
                }
                video.onpause = function(){
                    display.innerHTML = "Pausing......";
                }
            }
            function progressUpdate(){
                var postionBar = document.getElementById("postionBar");
                postionBar.style.width = (video.currentTime/video.duration * 100) + "%";
                display.innerHTML = Math.round((video.currentTime*100)/100) + "sec";
            }
            function play(){
                video.play();
            }
            function pause(){
                video.pause();
            }
            function stop(){
                video.pause();
                video.currentTime = 0;
            }
            function speedUp(){
                video.play();
                video.playbackRate = 2;
            }
            function slowDown(){
                video.play();
                video.playbackRate = 0.5;                
            }
            function normalSpeed(){
                                video.play();
                video.playbackRate = 1;    
            }
        </script>
    </head>
    
    <body>
    <div class="videoContainer">
        <video id="videoPlayer" ontimeupdate="progressUpdate()">
            <source src="resource/梦想.mp4" type="audio/mp4"></source>
        </video>
    </div>
            <div>
                <div id="durationBar">
                    <div id="postionBar">
                        <span id="displayStatus"></span>
                    </div>
                </div>
            </div>
            <button onclick="play()">Play</button>
            <button onclick="pause()">Pause</button>
            <button onclick="stop()">Stop</button>
            <button onclick="speedUp()">Fast</button>
            <button onclick="slowDown()">Slow</button>
            <button onclick="normalSpeed()">Normal</button>
    </body>
</html>

 

转载于:https://www.cnblogs.com/beautiful-code/p/5066096.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值