• mp4格式-播放和断点续播


     video 标签(autopaly自动播放属性)

       <video id="videoPlay" class="video" autoplay="autoplay" poster="" width="1200" height="100%" style="text-align: -webkit-center; margin: 0 auto;" controls="" preload="">
                            <source src="video/mp4/环保小视频.mp4" type="video/mp4">
                        </video>
    var time;
    var xutime;
    var CurrentTime;
    var RemainingTime;
    
    var video = document.getElementById('videoPlay');
    
    //播放结束事件
    video.onended = function () {
        console.log("视频播放完成");
        clearInterval(time);
        clearInterval(xutime);
    };
    
    //播放开始事件
    video.oncanplay = function () {
        console.log("视频播放开始");
        //播放总时长
        RemainingTime = video.duration.toFixed(0);
        console.log(RemainingTime);
        //是否可以续播
        var TimeInt = TimeIntervalSelect();
        //可以
        if (TimeInt > 0) {
            //播放进度加1秒后小于总时长,进入续播
            if (parseFloat(TimeInt) + 1 < parseFloat(RemainingTime)) {
                if (pd == 0) {
                    console.log(TimeInt);
                    ContinuedBroadcasting(TimeInt);
                    pd = 1;
                }
            } //不可以,插入播放进度
            else {
                TimeInterval();
            }
        }
            //不可以,插入播放进度
        else {
            TimeInterval();
        }
    }
    //断点续播(秒) function ContinuedBroadcasting(Second) { //断点续播播放进度推后一秒 $('video').prop('currentTime', parseFloat(Second) - 1);
       //播放 $(
    'video').trigger('play'); xutime = setInterval(function () { CurrentTime = video.currentTime.toFixed(1); //播放进度(单位:秒) console.log("续播进度:" + CurrentTime); InsetTimeInterval(CurrentTime); }, 1000); } //记录播放进度 function TimeInterval() { if (parseFloat(CurrentTime) > parseFloat(RemainingTime)) { clearInterval(time); } //轮询插入当前播放进度 time = setInterval(function () { CurrentTime = video.currentTime.toFixed(1); //当前播放进度(单位:秒) console.log("当前进度:" + CurrentTime); InsetTimeInterval(CurrentTime); }, 1000); } var id = 0; var pd = 0; $("video").click(function () { if (id == 0) { //播放暂停 $('video').trigger('pause'); id = 1; clearInterval(time); clearInterval(xutime); } else { //播放继续 $('video').trigger('play'); id = 0; TimeInterval(); } }) //获取进度 function TimeIntervalSelect() { var Progress; $.ajax({ url: "/Video/TimeSelect", type: 'GET', async: false, dataType: 'json', success: function (data) { Progress = data; } }); return Progress; } //插入进度 function InsetTimeInterval(CurrentTime) { $.ajax({ url: "/Video/Time", data: {CurrentTime: CurrentTime }, type: 'POST', async: false, dataType: 'json', success: function (data) { } }); }
  • 相关阅读:
    51 nod 1181 质数中的质数(质数筛法)
    Just oj 2018 C语言程序设计竞赛(高级组)F:Star(结构体排序+最小生成树)
    欧拉函数+费马小定理拓展
    ZOJ 3785 What day is that day?(数论:费马小定理)
    Just oj 2018 C语言程序设计竞赛(高级组)H: CBT?
    树链剖分(入门学习)
    bitset用法
    链式前向星
    Nearest Common Ancestors(LCA板子)
    LCA(最近公共祖先)
  • 原文地址:https://www.cnblogs.com/-Fly/p/7525591.html
Copyright © 2020-2023  润新知