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 + '″'
            }

 

posted @ 2020-09-18 17:44  栀夏。  阅读(2971)  评论(0编辑  收藏  举报