获取Audio音频的总时长
作者:互联网
let musicDom = document.getElementsByTagName('audio')[0]; // 获取AudioDom节点
musicDom.load();//因为source标签不能直接更改路径,所以整个audio标签必须重新加载一次
musicDom.oncanplay = function () {
console.log("音乐时长",musicDom.duration);//音乐总时长
//处理时长
var time = musicDom.duration;
//分钟
var minute = time / 60;
var minutes = parseInt(minute);
if (minutes < 10) {
minutes = "0" + minutes;
}
//秒
var second = time % 60;
var seconds = Math.round(second);
if (seconds < 10) {
seconds = "0" + seconds;
}
console.log('处理音乐时长',minutes+":"+seconds)
}
标签:musicDom,seconds,总时长,音频,60,time,var,Audio,minutes 来源: https://www.cnblogs.com/0826sw/p/11915291.html