HTML5 onclick播放音频,如何一次播放一个?
单击按钮时,正在播放音乐,但如果再次单击该按钮或另一个按钮。 2 个或更多曲目将同时播放。
<script> var audio17 = new Audio("/system/voicefiles/1/original/(01) [BT feat. Jes] Every Other Way (Armin van Buuren Remix).mp3?1297492411")</script>
<div style="float:right"><input onclick="audio17.play();" type="button" value="spk" /> </div>
<script> var audio18 = new Audio("/system/voicefiles/2/original/audio2.mp3")</script>
<div style="float:right"><input onclick="audio18.play();" type="button" value="spk" /> </div>
如何确保只播放一种声音?我应该使用 mutax 还是其他东西?
When button is clicked on music is playing, but if you hit the button again, or another button. 2 or more tracks will be playing at the same time.
<script> var audio17 = new Audio("/system/voicefiles/1/original/(01) [BT feat. Jes] Every Other Way (Armin van Buuren Remix).mp3?1297492411")</script>
<div style="float:right"><input onclick="audio17.play();" type="button" value="spk" /> </div>
<script> var audio18 = new Audio("/system/voicefiles/2/original/audio2.mp3")</script>
<div style="float:right"><input onclick="audio18.play();" type="button" value="spk" /> </div>
How to make sure only one sound is playing? should I use a mutax or something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试为所有音频元素创建一个数组。在播放新文件之前,请确保停止任何其他音频对象(循环遍历已保存的音频对象数组并在播放下一个音频文件之前停止播放)。
Try to create an array for all of your audio elements. Before playing a new file, make sure any other audio objects are stopped (loop through the array of saved audio objects and stop their playback before playing the next audio file).