admin管理员组文章数量:1295323
I am using websocket using vuejs like below.
socket would run when it gets 'any' on realtime.
And it gets data from rest api
When data.get is true, I want to make a short alarm sound like 'dingdong'.
How can I make this using vuejs? Could you remend some advice? Thank you so much for reading it.
socket.on("any", async order =>{
const data = await axios.post('/', {order})
if(data.get === true){
return ... // <-- some alarm occurs like 'dingdong'
}
}
)
I am using websocket using vuejs like below.
socket would run when it gets 'any' on realtime.
And it gets data from rest api
When data.get is true, I want to make a short alarm sound like 'dingdong'.
How can I make this using vuejs? Could you remend some advice? Thank you so much for reading it.
socket.on("any", async order =>{
const data = await axios.post('/', {order})
if(data.get === true){
return ... // <-- some alarm occurs like 'dingdong'
}
}
)
Share
Improve this question
asked Nov 12, 2019 at 7:40
DD DDDD DD
1,2382 gold badges14 silver badges42 bronze badges
1
- Vue is just javascript, so any solution in javascript should work in vue as well. Doing a quick google search on "play sounds using javascript" brings multiple results. – Nikolaj Dam Larsen Commented Nov 12, 2019 at 7:49
3 Answers
Reset to default 7you can play any sound in vuejs like this:
Html:
<div id="app">
<button @click.prevent="playSound()">Play Sound</button>
</div>
js / vue:
var data = { soundurl : 'http://soundbible./mp3/analog-watch-alarm_daniel-simion.mp3'}
new Vue({
el: '#app',
data: data,
methods: {
playSound () {
var audio = new Audio(data.soundurl);
audio.play();
}
}
});
Your sound obviously needs to be hosted online to achieve it that way.
Hope it helps!
As far as I know there is a possibility to play audio in Vue, so that you can insert a specific ringtone of your choice (.mp3, .wav, ...).
But tbh personally I don't know how to code that.
HowlerJS may help you, if you want to read something more about that, seems to be easy to use.
You can achieve that with pure JS, without any other library.
var audioFile = new Audio('your_audio_file.wav');
audioFile.play();
Of course you can implement that in your own method to let this be accessible from somewhere else...
本文标签: javascriptHow to make alarm sound using vuejsStack Overflow
版权声明:本文标题:javascript - How to make alarm sound using vuejs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741617053a2388583.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论