【问题标题】:Html video playlistHtml 视频播放列表
【发布时间】:2013-03-14 23:55:49
【问题描述】:

我的页面上有一个视频播放器,可以根据按下的链接播放视频。

我正在尝试创建它,以便它还能够根据另一个按钮跳到视频的某个部分。

到目前为止,我让他们都在不同的页面上工作。 这是我到目前为止所拥有的:

<div id="video-player"> 

       <img src="images/videoplayer/screen680.png" id="video-screen"/>    
      <video id="videoarea" poster="" src=""></video>

      <ul id="playlist">
        <li movieurl="video/1.Adele Gillies_short_compressed.mp4" id="myvideo">

            <button class="video-button left-menu"  id="education-jump">vid1 education</button>
            <button class="video-button left-menu" id="education-jump2">vid2 eductaion</button>
        </li>

        <li movieurl="video/1.William Morrison_short-comp.mp4" id="myvideo2">
            <button class="video-button left-menu"  id="relationship-jump">vid1 relationships</button>
            <button class="video-button left-menu" id="relationship-jump2">vid2 relationships</button>
        </li>


      </ul>
  </div> 

 <script> 
            var myvideo = document.getElementById("myvideo"),
            playbutton = document.getElementById('playme'),
            jumplink1 = document.getElementById('education-jump');
            jumplink2 = document.getElementById('education-jump2');


        jumplink1.addEventListener("click", function (event) {
            event.preventDefault();
            myvideo.play();
            myvideo.pause();
            myvideo.currentTime = 200;
            myvideo.play();
        }, false);

         jumplink2.addEventListener("click", function (event) {
            event.preventDefault();
            myvideo.play();
            myvideo.pause();
            myvideo.currentTime = 170.1;
            myvideo.play();
        }, false);





    </script>

<script type="text/javascript">
          $(function() {
    $("#playlist li").on("click", function() {
        $("#videoarea").attr({
            "src": $(this).attr("movieurl"),
            "poster": "",
            "autoplay": "autoplay"
        })
    })
    $("#videoarea").attr({
        "src": $("#playlist li").eq(0).attr("movieurl"),
        "poster": $("#playlist li").eq(0).attr("moviesposter")
    })
})
        </script>

【问题讨论】:

  • 你的问题是什么?
  • 如何跳到视频的某个部分,同时仍然能够在页面上播放多个视频

标签: jquery video playlist


【解决方案1】:

这会将事件附加到按钮(而不是 &lt;li&gt;),但仍会从父组中读取 URL,但会从用于触发加载的按钮中设置假时间属性

为避免过多闪烁,它还会检查视频是否正在更改(在这种情况下,它会重新加载整个视频)或者视频是否相同,只是一个新位置,它所做的只是改变当前时间。

我想这就是你所追求的......

     <div id="video-player"> 

      <video id="videoarea" poster="" src="" proload="auto" controls></video>

      <ul id="playlist">
        <li movieurl="video.mp4" id="myvideo">
            <button class="video-button left-menu"  id="education-jump" time="20">vid1 education</button>
            <button class="video-button left-menu" id="education-jump2" time="30">vid2 eductaion</button>
        </li>

        <li movieurl="video2.mp4" id="myvideo2">
            <button class="video-button left-menu" id="relationship-jump" time="10">vid1 relationships</button>
            <button class="video-button left-menu" id="relationship-jump2" time="50">vid2 relationships</button>
        </li>

      </ul>
  </div> 

<script> 
    var myvideo = document.getElementById("videoarea")

    $(".video-button").on("click", function() {
        // if we need to load a new video do so
        if ($("#videoarea").attr("src") != $(this).parent().attr("movieurl")) {
            $("#videoarea").attr({
                "src": $(this).parent().attr("movieurl"),
                "poster": "",
                // load a fake attribute with the desired start time
                "starttime": $(this).attr("time")})
            $("#videoarea").on("canplay",function() {
                // set the current time to the fake attribute
                myvideo.currentTime=$(this).attr("starttime")
                myvideo.play();
                // remove the event to stop it triggering multiple times
                $("#videoarea").off("canplay")
            })
        } else {
            // if the video URL didn't change, just adjust the time
            myvideo.currentTime=$(this).attr("time")
        }
    })

 </script> 

【讨论】:

  • 我的荣幸。希望它有意义,您可以根据需要对其进行扩展。
  • 只是一个简短的小问题,是否可以在每个部分的特定时间暂停或停止视频?
  • 我会在这里快速查看我的答案 - stackoverflow.com/questions/15435976/… ...该示例中的代码显示了如何使用 timeupdated 事件在某些点做出反应
  • 如果文件名相同,我会从
  • 中去掉 .mp4,然后在添加源时为 video1.mp4 添加一个,为 video1.ogv 添加一个,或使用 canPlayType 方法来确定应该使用哪个
  • 看看这个修改版的答案 - jsfiddle.net/FBzwq 它会检测浏览器是否支持 .mp4,如果不支持则回退到 .ogg 版本(也可以通过添加对 WebM 的检测测试video/webm; codecs="vp8, vorbis"
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签