HTML5 Audio Player Duration Showing Nan

前端 未结 1 1253
礼貌的吻别
礼貌的吻别 2020-12-31 05:40

I just started to learn HTML5 and was going through HTML5 Audio player using JQuery. I coded a player with Playlist, everything works fine except the Duration with help of w

相关标签:
1条回答
  • 2020-12-31 06:40

    Use the loadedmetadata event listener to get the duration for the audio as soon as the metadata is loaded. Do something like the following code:

    var audio = new Audio();
    audio.src = "mp3/song.mp3";
    audio.addEventListener('loadedmetadata', function() {
        console.log("Playing " + audio.src + ", for: " + audio.duration + "seconds.");
        audio.play(); 
    });
    
    0 讨论(0)
提交回复
热议问题