HTML5 Audio Player Duration Showing Nan

蹲街弑〆低调 提交于 2019-11-30 08:29:17

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(); 
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!