0
我有下面的代碼打印到控制檯,當視頻播放5秒。但是,如果用戶暫停視頻並再次按下播放,則會將其打印到控制檯。如何收聽YouTube視頻從未播放到播放5秒的時間?
當狀態從未啓動狀態變爲播放狀態5秒時,如何才能打印到控制檯?
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
if (newState == 1) {
setTimeout(function(){
current = ytplayer.getCurrentTime();
console.log(current);
}, 5000);
}
}