H5-新增标签-video

video标签简介

作用主要用来承载视频格式的标签
Video替代flash 视频

//基本用法
<video></video>

video的基本属性

行盒:默认w300,h150
src:用来链接视频地址(至少提供两种视频格式文件,避免出现视频格式不兼容问题:flv,swf,ogg,webm,mp4)
controls:视频默认控件(Boolean 有暂停,播放,声音,倍速,全屏等功能,但每个浏览器显示不同)
autoplay单独设置无效果需使用方法;
controls:是否显示播放控件,不同浏览器控件外观不一致;
currentTime:0 当前播放的时间点,可赋值跳转
duration:视频总时长(s);
ended:boolean,是否播放完成
loop:是否循环播放
muted:是否静音(静音后浏览器可以自动播放)
volum:0-1,音量设置,默认是最大值,且是js对象属性,不能在标签上直接写。
pasued:当前是否处于暂停状态
poster:指定视频的第一帧为海报
metadata 元数据只预加载视频宽度,时长,第一帧内容
auto:自动预加载,时长,第一帧内容,并缓冲一段时长
none:任何内容不加载

各浏览器对视频格式的兼容
在这里插入图片描述

//多格式
<video>
<source src='res/birdes.mp4'/>
<source src='res/birdes.webm'/>
<source src='res/birdes.ogg'/>\
你的浏览器不支持video标签
</video>

Video方法

play(); 播放方法
pause():暂停方法

video案例

video自定义控件

在这里插入图片描述

//js代码
// 获取video
    var ovideo = document.querySelector('video');
    var play = document.querySelector('.paly');
    // 时间
    var otimer = document.querySelector('.timer');
    // 进度
    var progress_bar = document.querySelector('.progress_bar');
    var nowprogress_bar = document.querySelector('.progress_bar div');
    var nowprogress_icon = document.querySelector('.progress_bar i');
    var timer = null;
    // 倍速
    var quick = document.querySelector('.suit');
    var quick_list = document.querySelector('.suit ul');
    var quick_list_item = document.querySelectorAll('.suit ul li');
    // 音量
    var addsound = document.querySelector('.sound-add');
    var liltsound = document.querySelector('.sound-liit');
    var stopsound = document.querySelector('.sound-stop');
    // 全屏
    var allvidedo = document.querySelector('.allvidedo');

    // 视频播放和暂停
    function start() {
        play.onclick = function() {
            if (ovideo.paused) {
                ovideo.play();
                this.style.backgroundImage = "url('./暂停.png')";
                timer = setInterval(function() {
                    // 总时长
                    var total = ovideo.duration;
                    // 现在时长
                    var nowtime = ovideo.currentTime;
                    //更新
                    otimer.innerHTML = `${parseInt(nowtime/60)}:${String(parseInt(nowtime%60)).padStart(2,0)}/${parseInt(total/60)}:${String(parseInt(total%60)).padStart(2,0)}`;

                    // 当前播放的长度
                    var nowprogress_barWidth = nowtime / total * progress_bar.clientWidth;
                    nowprogress_bar.style.width = nowprogress_barWidth + 'px';
                    nowprogress_icon.style.left = nowprogress_barWidth - 3 + 'px';
                }, 30);
            } else {
                ovideo.pause();
                this.style.backgroundImage = "url('./播放.png')";
                clearInterval(timer);
            }
        }
    }
    // 进度条
    progress_bar.onclick = function(e) {
            var location = e.layerX;
            console.log(location);
            var width = this.clientWidth;
            var targetTime = location / width * ovideo.duration;
            // 给video设置当前时间
            ovideo.currentTime = targetTime;
        }
        // 倍速
    quick.onclick = function() {
        quick_list.style.display = 'block';
    }
    quick_list.onmouseleave = function() {
        quick_list.style.display = 'none';
    }
    for (var i = 0; i < quick_list_item.length; i++) {
        quick_list_item[i].index = i;
        quick_list_item[i].onclick = function() {
            switch (this.index) {
                case 0:
                    // 两倍
                    ovideo.playbackRate = 2;
                    break;
                case 1:
                    //1.5
                    ovideo.playbackRate = 1.5;
                    break;
                case 2:
                    //1.25
                    ovideo.playbackRate = 1.25;
                    break;
                default:
                    //正常
                    ovideo.playbackRate = 1;
                    break;
            }

        }
    }
    addsound.onclick = function() {
        ovideo.volume = ovideo.volume + 0.1 >= 1 ? 1 : ovideo.volume + 0.1;
    };
    liltsound.onclick = function() {
        ovideo.volume = ovideo.volume - 0.1 <= 0 ? 0 : ovideo.volume - 0.1;
    };
    stopsound.onclick = function() {
        if (ovideo.volume == 0) {
            ovideo.volume = 1;
            stopsound.style.backgroundImage = "url('./静音.png')";
        } else {
            ovideo.volume = 0;
            stopsound.style.backgroundImage = "url('./静音 (1).png')";
        }
    };
    // 全屏
    allvidedo.onclick = function() {
        ovideo.webkitRequestFullScreen();
    }
    start();
video标签中的视频播放进度可以通过JavaScript来控制和获取。可以使用video元素的currentTime属性来获取或设置当前的播放时间(以秒为单位)。通过监听video元素的timeupdate事件,可以实时获取视频播放的进度并更新进度条的显示。具体实现方法如下: 1. 首先获取video元素的引用,可以通过document.getElementById()或document.querySelector()方法来获取。 2. 给video元素添加一个timeupdate事件监听器,当视频播放时间更新时触发。 3. 在事件监听器内部,可以通过video.currentTime属性获取当前的播放时间。 4. 根据视频的总时长(video.duration属性)计算出进度百分比(当前播放时间/总时长),用于更新进度条的显示。 5. 可以使用HTML和CSS来创建一个进度条,通过JavaScript更新其宽度或位置来反映视频播放的进度。 综上所述,您可以使用上述方法来实现video标签视频播放进度的控制和显示。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [video标签播放视频无法拖动进度条(使用nginx解决)](https://blog.csdn.net/qq_34465338/article/details/124623067)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Html5新增标签video视频,实现音视频的播放、暂停、快进、慢进、倍速等操作](https://blog.csdn.net/qq_51066068/article/details/124413984)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [H5html5 video)视频播放禁止拖动进度条,不能快进,不能后退;微信公众号视频播放;Java视频流播放](https://download.csdn.net/download/weixin_43992507/14503320)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值