[英]Audio mute and unmute button in html
I am creating an HTML page with multiple audios.我正在创建一个带有多个音频的 HTML 页面。 I want a mute button which can mute all audios of that page together so that even we play another audio even if it plays but we can not hear anything.
我想要一个静音按钮,它可以将该页面的所有音频一起静音,这样即使我们播放另一个音频,即使它播放但我们什么也听不到。
I am referring the code mentioned here .我指的是这里提到的代码。
But it only creates a Toggle button, but not mute the audio.但它只创建一个切换按钮,而不是静音。
The audio tags used on the page are like below:页面上使用的音频标签如下:
<audio id="audio_playo24">
<source src="voice/vo3.mp3" type="audio/mp3" />
</audio>
Can anyone please point me in the correct direction?谁能指出我正确的方向?
Thank you.谢谢你。
Try once with this code it will work fine.使用此代码尝试一次它会正常工作。
JavaScript Code JavaScript 代码
function toggleMute() {
var myAudio = document.getElementById('audio_playo24');
myAudio.muted = !myAudio.muted;
}
HTML Code HTML 代码
<audio id="audio_playo24" controls>
<source src="voice/vo3.mp3" type="audio/mp3" />
</audio>
<a href="javascript:void(0);" onclick="toggleMute()">Mute/Unmute</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.