报警音频下载地址:
https://hd1080.pro/?s=%E6%8A%A5%E8%AD%A6
方法一:
该方法在页面中不会显示播放工具
html:
<div id="app">
<button @click.prevent="playSound()">Play Sound</button>
</div>
js:
1:首先在script中定义soundData
var soundData= { soundurl :'http://soundbible.com/mp3/analog-watch-alarm_daniel-simion.mp3'}
let audio =new Audio( soundData.soundurl);
2:在methods中调用播放和暂停方法
methods: {
playSound () {//播放
audio.play();
} ,
pauseSound(){// 暂停
audio.play();
}
}
方法二:
html:
<audio controls="controls" hidden src="./dd.mp3" ref="audio"></audio>
<el-button type="warning" icon="el-icon-edit" @click="startplay">开始播放</el-button>
script:
methods:{
startPlay(){//开始播放
this.$refs.audio.currentTime = 0; //从头开始播放提示音
this.$refs.audio.play(); //播放
},
pausePlay(){//暂停播放
this.$refs.audio.pause(); //暂停
}
}
网友评论