vue中 根据音频 获取音频的时长
<template> <audio ref="audioUrlRefText" :src="fileUrl"/> </template>
方法中:
clientGetRadioTime () { let audio = this.$refs.audioUrlRefText if (audio.readyState > 0) { let seconds = parseInt(audio.duration % 60) let ss = parseFloat((audio.duration - seconds).toFixed(3)) let sum = ss + seconds return sum + '″' } },
或者:
const audio = new Audio(audioUrl) audio.load() audio.oncanplay = () => { console.log('audio.duration', audio.duration) this.playRadioTime = audio.duration + '″' }