说明:
**
涉及:
vue js html5中audio 自动播放音频
目的:
手机端,兼容ios
打开https链接就播放。**
//失败 代码
<template>
<div class="main">
<audio
:src="video"
ref="audio"
id="eventAudio"
controls="controls"
autoplay="autoplay"
/>
</div>
</template>
<style lang="less" scoped>
</style>
<script>
export default {
data(){
return{
video:'',
}
},
mounted(){
document.addEventListener('click',this.audio_but(),false)
},
methods:{
audio_but(){
var that = this;
let audio;
audio = document.getElementById("eventAudio");
that.video="https://xb.api.mytext.world/uploads/xb/MP3/1.mp3"
console.log("开始播放---》audio===================="+audio);
audio.paly;
if(audio.ended){
console.log("播放完成---》audio===================="+audio);
that.video=''
that.$refs.audio.src=''
}else{
console.log("播放还没完成---》audio===================="+audio.ended);
}
},
},created(){
}
}
</script>