use*_*461 14 html javascript google-chrome html5-video
我想在HTML5中设置视频的时间位置.时间应该设置如下:
function settime(){
var video = document.getElementById("video1");
console.log(video.currentTime); //----->output for example 15.3
video.currentTime = 10.0;
console.log(video.currentTime);//----->>output always 0
}
Run Code Online (Sandbox Code Playgroud)
视频嵌入如下:
<button onclick="settime();">Set Time</button>
<div class="container">
<video id="video1" class="video-js vjs-default-skin" muted>
<source src="video.m4v" type="video/mp4" />
HTML5 Video is required for this example.
</video>
Run Code Online (Sandbox Code Playgroud)
但出于某种原因,这总是在Chrome中将currentTime重置为0.
设置currentTime时为什么要重置时间?如何正确设置currentTime?
我终于找到了答案!Chrome 要求您将 currentTime 设置为字符串,而不是数字。
function settime() {
var video = document.getElementById("video1");
console.log(video.currentTime); // output 0
video.currentTime = 10.0;
console.log(video.currentTime); // output 0 for some chrome users or 10 for firefox and others
video.currentTime = "10.0";
console.log(video.currentTime); // output 10
}
settime();Run Code Online (Sandbox Code Playgroud)
<audio id="video1" src="https://sample-videos.com/audio/mp3/crowd-cheering.mp3" controls></audio>
<div>Click play to start the audio at 10 s.</div>Run Code Online (Sandbox Code Playgroud)
这在很多情况下是由服务器没有回复Accept-Ranges标头引起的。出于一个晦涩的、仅与 Google 开发人员相关的原因(FF 人员似乎并没有因为没有Accept-Ranges标头的服务器回复而受到冒犯),当没有提供这样的标头时,他们拒绝实施搜索。您可以通过使用 nginx 代理并添加proxy_force_ranges on;(服务器或位置都有效)来非常轻松地添加一个(至少用于测试)。
neo*_*yte -3
它应该是
var video = document.getElementById("video1");
Run Code Online (Sandbox Code Playgroud)
正如你所拥有的
<video id="video1" class="video-js vjs-default-skin" muted>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2497 次 |
| 最近记录: |