0
我有一些代碼,我得到的當前時間和持續時間,但是這兩個時間似乎是錯誤的,持續時間比普通視頻更長,當前時間似乎太快,它也永遠不會達到總持續時間量並稍微停止。JS - Youtube Iframe API返回錯誤的當前時間和持續時間?
代碼:
<script type="text/javascript">
var tag = document.createElement('script');
tag.id = 'iframe-demo';
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady(event) {
player = new YT.Player('existing-iframe-example', {
events: { // Setup the events to use
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
function onPlayerReady(event) {
event.target.playVideo(); // Auto play the video when ready
}
var myTimer;
function onPlayerStateChange(event){
if(event.data==1) { // playing
myTimer = setInterval(function(){
document.getElementById("time").innerHTML = (player.getCurrentTime()/60.0000).toFixed(2);
document.getElementById("duration").innerHTML = (player.getDuration()/60.0000).toFixed(2);
}, 100); // 100 means repeat in 100 ms
}
else { // not playing
clearInterval(myTimer);
}
}
}
</script>
如何這個問題能解決?
要顯示十進制表示,實際的十進制表示? – Viney