vue中audio实现微信语音播放动画
预览思路拿到时长做倒计时,时长 = ( 时长 + 1 ) * 100; destroy的时候清除一下代码<div style="display:none"><audio controls="controls" ref="audio"><source :src="url || ''" type="audio/mpeg" /><...
·
预览
思路
拿到时长做倒计时,时长 = ( 时长 + 1 ) * 100; destroy的时候清除一下
代码
<div style="display:none">
<audio controls="controls" ref="audio">
<source :src="url || ''" type="audio/mpeg" />
</audio>
</div>
<div class="voice-bg" @click="handlePlay">
<img
v-if="isPlaying"
src="./../../assets/images/goods/voice-play.gif"
alt=""
/>
<img
v-else
src="./../../assets/images/goods/voice.png"
alt=""
/>
<span>{{ duration || 0 }}"</span>
</div>
data() {
return {
url: '',
timer: null,
isPlaying: false,
currentTime: 0,
}
},
methods:{
handlePlay() {
let audio = this.$refs.audio;
if (!this.isPlaying) {
audio.play();
this.isPlaying = true;
this.watchEnd();
} else {
audio.pause();
clearTimeout(this.timer);
this.isPlaying = false;
audio.currentTime = 0;
}
},
watchEnd() {
let that = this;
this.timer = setTimeout(() => {
that.isPlaying = false;
}, (that.duration + 1) * 1000);
},
},
beforeDestroy() {
clearTimeout(this.timer);
}
资料
关于获取audio信息接口
this.$axios.get(`${this.info.url}?avinfo`).then(res => {
let { streams } = res.data;
this.duration = parseInt((streams && streams[0].duration) || 0);
});
UI图片
更多推荐
已为社区贡献11条内容
所有评论(0)