zoukankan      html  css  js  c++  java
  • video设置视频的播放位置(本例中实现效果是视频第一次播放完成后,接下来中从视频的中间部位开始循环播放)

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    <video id="mediaElementID" width="100%" height="100%" autoplay="autoplay"  controls="controls" >
        <source src="http://www.runoob.com/try/demo_source/mov_bbb.mp4" type="video/mp4">
    </video>
    </body>
    <script>
        var myVid=document.getElementById("mediaElementID");
        function getCurTime()
        {
            alert(myVid.currentTime);
        }
        function setCurTime()
        {
            myVid.currentTime=8;
        }
        myVid.addEventListener('ended',function(){
            setCurTime();
            myVid.play()
        },false);
    </script>
    </html>
    设置currentTime

    注:设置currentTime的方式,video的视频的src地址必须是线上的,本地的地址不会起作用

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            #playervideo{
                width:500px;
                height:300px;
                margin:20px auto;
                background:red;
            }
            #playervideo video{
    
            }
        </style>
    </head>
    <body>
    <div id="playervideo" class="portfolio-slideshow flexslider animate-onscroll">
        <video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" poster="video/demo.jpg" data-setup="{}" height="300" width="100%">
            <source src="artanis-large.mp4" type='video/mp4' />
        </video>
    </div>
    </body>
    <script language="javascript">
        var vList = ['movie.mp4', 'artanis-large.mp4', 'movie.mp4']; // 初始化播放列表
        var vLen = vList.length; // 播放列表的长度
        var curr = 0; // 当前播放的视频
    
        var video = document.getElementById("example_video_1");
    
        /*var video = document.createElement("VIDEO");
         video.setAttribute("width", "100%");
         video.setAttribute("height", "500");
         video.setAttribute("id", "example_video_1");
         video.setAttribute("class", "video-js vjs-default-skin");
         video.setAttribute("preload", "none");
         video.setAttribute("poster", "video//demo.jpg");
         video.setAttribute("data-setup", "{}");
         video.setAttribute("controls", "yes");
         document.getElementById("playervideo").appendChild(video);*/
        //document.body.appendChild(video);
    
        video.addEventListener('ended', play);
        play();
        function play(e) {
            video.src = vList[curr];
            video.load();
            video.play();
            curr++;
            if(curr >= vLen){
                curr = 0; // 播放完了,重新播放
            }
    
        }
    </script>
    <!-- /Video player -->
    </html>
    通过两个视频实现

    注:通过两个视频连续播放,poster需要设置一个两个视频衔接处比较接近的图片,禁止黑屏

    第二个例子也可以用来实现多个视频连续播放

  • 相关阅读:
    如何设计一个安全的对外接口?
    Java架构师必须知道的 6 大设计原则
    Spring Boot 如何快速改造老项目?
    Java 类中可以覆盖静态方法吗?
    Dubbo 的心跳设计,值得学习!
    在滴滴和头条干了 2 年后端开发,太真实…
    别乱提交代码了,看下大厂 Git 提交规范是怎么做的!
    3种骚操作,教你查看 Java 字节码!
    sysbench测试服务器性能
    mysql DDL时出现的锁等待状态
  • 原文地址:https://www.cnblogs.com/dongxiaolei/p/7094464.html
Copyright © 2011-2022 走看看