无法在html5视频中使用jquery / javascript设置video.currentTime

无法在html5视频中使用jquery / javascript设置video.currentTime

问题描述:

无论是从控制台还是从我的标记中,我都无法使用javascript设置html5视频元素的当前时间。我也在使用jQuery,但我不知道这是否与问题相关。我在Ubuntu上使用Google Chrome 24.0.1312.57;下面是我想要做的一个例子

Either from the console or from in my tags, I cannot set the current time of an html5 video element with javascript. I also am using jQuery but I do not know if that is relevant to the issue. I am using Google Chrome 24.0.1312.57 on Ubuntu; below is an example of what I am trying to do

<html>
<script type="text/javascript">
    var video = document.getElementById("video");
    var videoSourceString = "<source src=http://URL:PORT" + path + " type='video/mp4'></source>";
    $(video).html(videoSourceString);
    video.load();
    var frameRate = 24;
    video.currentTime += 1/frameRate;// doesn't do anything, leaves currentTime same as before
</script>
<body>
<video id="video">
</video>
</body>
</html>

视频播放和暂停状态良好,但每当我尝试手动更改时间时都不起作用。

The video plays and pauses fine, but whenever I try to manually change the time it does not work.

我已经看过 HTML5视频 - Chrome - 错误设置currentTime 并且控制台中不存在此类错误,实际上它不显示任何错误。我也无法使用video.currentTime + = 1或document.getElementById(video)。currentTime = 0使用任何数字从控制台更改当前时间。

I already looked at HTML5 Video - Chrome - Error settings currentTime and no such errors are present in the console, in fact it does not display any errors. I also cannot change the currentTime from the console using video.currentTime += 1 or document.getElementById("video").currentTime = 0 with any number.

谢谢非常多!

尽管我一直等到loadedmetadata事件发生,但结果却是缺乏对web.py的HTTP字节范围请求阻止了寻找。需要HTTP字节范围请求才能在HTML5视频中查找,并且事实证明web.py不支持它们,所以我使用Apache为视频提供服务,并且它的工作无懈可击。感谢您的回应!

Even though I was waiting until the loadedmetadata event was reached, it turned out to be the lack of support for HTTP byte range requests by web.py that was preventing seeking. HTTP Byte Range requests are required to seek in HTML5 video and it turns out web.py does not support them, so I served the video using Apache and it worked flawlessy. Thank you for your responses!