寻求html5视频中的一点

dam*_*mon 32 seek html5-video

是否有可能寻找html5 video网页中显示的特定点?我的意思是,我可以输入一个特定的时间值(比方说01:20:30:045)并让玩家控制(滑块)移动到该点并从那一点开始玩吗?

在旧版本的mozilla中vlcplugin我认为这可以通过方法实现seek(seconds,is_relative)..但我想知道这是否可以在html视频中使用.

编辑:

我创建了带有视频的页面,并添加了如下所示的javascript.当我点击链接时,它会显示点击的时间..但它不会增加播放位置..但继续正常播放.

视频播放位置不应该更改吗?

HTML

<video id="vid" width="640" height="360" controls>
       <source src="/myvid/test.mp4" type="video/mp4" /> 
</video>
<a id="gettime" href="#">time</a>
<p>
you clicked at:<span id="showtime"> </span> 
</p>
Run Code Online (Sandbox Code Playgroud)

JavaScript的

$(document).ready(function(){
    var player = $('#vid').get(0);
    $('#gettime').click(function(){
            if(player){
                current_time=player.currentTime;
                $('#showtime').html(current_time+" seconds");
                player.currentTime=current_time+10;
            }
        });
}
);
Run Code Online (Sandbox Code Playgroud)

Thi*_*ter 50

您可以使用v.currentTime = seconds;寻找给定的位置.

参考:https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/currentTime


rog*_*ack 7

不幸的是,对于某些电影元素,它的表现似乎与其他元素不同。例如,对于 amazon video_element,您似乎必须先调用 pause,然后才能找到任何地方,然后调用 play。但是,如果您在设置后调用播放“太快”,currentTime则它不会粘住。奇怪的。

这是我目前的工作:

function seekToTime(ts) {
  // try and avoid pauses after seeking
  video_element.pause();
  video_element.currentTime = ts; // if this is far enough away from current, it implies a "play" call as well...oddly. I mean seriously that is junk.
    // however if it close enough, then we need to call play manually
    // some shenanigans to try and work around this:
    var timer = setInterval(function() {
        if (video_element.paused && video_element.readyState ==4 || !video_element.paused) {
            video_element.play();
            clearInterval(timer);
        }       
    }, 50);
}
Run Code Online (Sandbox Code Playgroud)