How can I get the html5 audio's duration time

前端 未结 8 1536
忘掉有多难
忘掉有多难 2020-12-09 15:10

I have a html5 tag in page, but how can I know its duration time?

8条回答
  •  醉话见心
    2020-12-09 15:26

    var au = document.createElement('audio');
    au.addEventListener('loadedmetadata',function(){
        au.setAttribute('data-time',au.duration);
    },false);
    

提交回复
热议问题