HTML 5 视频播放器用给定的数字更新当前时间
HTML 5 video player update currentTime with given number
我想用用户
给定的号码更新currentTime
例如我有一个 18.20 分钟的视频,当用户输入 1.46 时,它应该从 1.46 分钟开始播放视频,如果用户输入 4.56 分钟,它应该从 4.56 分钟开始播放
我正在尝试将给定的分钟数转换为数字,但我认为这是错误的
function minsToNumber(d) {
d = Number(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);
return ((h > 0 ? h + "." + (m < 10 ? "0" : "") : "") + m + "." + (s < 10 ? "0" : "") + s);
}
谁能给出正确的计算结果?
The HTMLMediaElement.currentTime property gives the current playback
time in seconds. Setting this value seeks the media to the new time.
所以如果你需要4分55秒,你必须使用这个值:4*60 + 55 = 295
var video = document.getElementById('video');
video.currentTime = 295; // seconds
完整示例:(与@Kaiido 合作创建)
var toSeconds = function(time) {
time = ('' + time).split('.');
return +time[0] * 60 + +time[1];
};
toSeconds('4.55'); // 295
toSeconds(4.55); // 295
我想用用户
给定的号码更新currentTime
例如我有一个 18.20 分钟的视频,当用户输入 1.46 时,它应该从 1.46 分钟开始播放视频,如果用户输入 4.56 分钟,它应该从 4.56 分钟开始播放
我正在尝试将给定的分钟数转换为数字,但我认为这是错误的
function minsToNumber(d) {
d = Number(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);
return ((h > 0 ? h + "." + (m < 10 ? "0" : "") : "") + m + "." + (s < 10 ? "0" : "") + s);
}
谁能给出正确的计算结果?
The HTMLMediaElement.currentTime property gives the current playback time in seconds. Setting this value seeks the media to the new time.
所以如果你需要4分55秒,你必须使用这个值:4*60 + 55 = 295
var video = document.getElementById('video');
video.currentTime = 295; // seconds
完整示例:(与@Kaiido 合作创建)
var toSeconds = function(time) {
time = ('' + time).split('.');
return +time[0] * 60 + +time[1];
};
toSeconds('4.55'); // 295
toSeconds(4.55); // 295