我想在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?
我正在尝试使用 HTML5 从给定的当前时间开始制作视频。我正在使用执行以下操作的 javascript 函数:
function goToMinute(params) {
var video = document.getElementById("video_tags");
video.currentTime = 100;
video.play();
}
Run Code Online (Sandbox Code Playgroud)
这个函数在点击时被调用,因为我有一个位置列表,当我点击它们时,我通过参数传递位置时间,然后我想从那里开始视频。
我已经检查过了,参数给了我我想要的数字,例如 10.10(以秒为单位)。
由于它不起作用,我尝试在那里放置一个值,就像我之前在代码中显示的那样:
video.currentTime = 100;
Run Code Online (Sandbox Code Playgroud)
调试我发现我的video.currentTime归因正在设置video.currentTime = 0并且视频从头开始。为什么会这样?
调用函数的代码:
<th><a onclick="goToMinute(<%= manual.time %>)"><%= manual.time %></a></th>
Run Code Online (Sandbox Code Playgroud)
我还可以添加已经在 Firefox、Chrome 和 Edge 中尝试过的内容。