I am creating an HTML page with multiple audios. 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.
CodePudding user response:
Try once with this code it will work fine.
JavaScript Code
function toggleMute() {
var myAudio = document.getElementById('audio_playo24');
myAudio.muted = !myAudio.muted;
}
HTML Code
<audio id="audio_playo24" controls>
<source src="voice/vo3.mp3" type="audio/mp3" />
</audio>
<a href="javascript:void(0);" onclick="toggleMute()">Mute/Unmute</a>