Javascript在MP3曲目持续时间内返回NaN:NaN

时间:2016-06-10 15:56:34

标签: javascript html mp3 innerhtml

所以...我正在用Javascript开发一个MP3播放器,一切都很好但是当我尝试使用innerHTMLT和" print" MP3文件的持续时间,而不是显示持续时间,显示它:NaN:NaN ...但是,当我发出一个对整个代码没有任何意义的警报时,它可以工作!

带有/不带alertu功能的代码:(第二个在警报的OK按钮点击后工作)

var track = document.getElementById('track');

var duration = document.getElementById('fullTime');
var currentTime = document.getElementById('currentTime');

//alert("AHHH!!!");

var minutes = parseInt(track.duration / 60);
var sec = parseInt(track.duration % 60);

duration.innerHTML = minutes + ":" + sec;

function playOrPause()
{
    if(!track.paused && !track.ended)
    {
        track.pause();
        document.getElementById('pause').style.display = "none";
        document.getElementById('play').style.display = "inline";
    }
    else
    {
        track.play();
        document.getElementById('play').style.display = "none";
        document.getElementById('pause').style.display = "inline";
    }
}

function muteOrUnmute()
{
    if(track.muted == true)
    {
        track.muted = false;
        document.getElementById('mute').style.display = "none";
        document.getElementById('unmute').style.display = "inline";
    }
    else
    {
        track.muted = true;
        document.getElementById('mute').style.display = "inline";
        document.getElementById('unmute').style.display = "none";
    }
}

0 个答案:

没有答案