Youtube API getCurrentTime() 以毫秒为单位?
Youtube API getCurrentTime() in milliseconds?
我正在使用 Youtube API 在视频下方显示字幕。每当视频为 stopped/started 或移动位置时,我都会使用 getCurrentTime() 来获取时间,但它仅提供整秒的值。当我想快速改变字幕时,我需要一个更精确的方法来获取时间,有没有办法以毫秒为单位?
getTime() 函数应该return 视频的当前时间,以秒为单位,后跟毫秒,例如视频提前暂停时为 2.1313131。 api 演示的修改后的代码片段在控制台中显示了这一点。
我不确定您是否设置了任何时间间隔,或者不小心将时间转换为整数。
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
var videotime = 0;
event.target.playVideo();
function updateTime() {
console.log(player.getCurrentTime());
}
timeupdater = setInterval(updateTime, 0);
}
我正在使用 Youtube API 在视频下方显示字幕。每当视频为 stopped/started 或移动位置时,我都会使用 getCurrentTime() 来获取时间,但它仅提供整秒的值。当我想快速改变字幕时,我需要一个更精确的方法来获取时间,有没有办法以毫秒为单位?
getTime() 函数应该return 视频的当前时间,以秒为单位,后跟毫秒,例如视频提前暂停时为 2.1313131。 api 演示的修改后的代码片段在控制台中显示了这一点。 我不确定您是否设置了任何时间间隔,或者不小心将时间转换为整数。
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
var videotime = 0;
event.target.playVideo();
function updateTime() {
console.log(player.getCurrentTime());
}
timeupdater = setInterval(updateTime, 0);
}