Hello i want to make a button that mutes and unmutes sound in html5 tag.
Here what i have so far. Sadly it doesnt work

.ts

soundOnOff()
{
    let audio = document.getElementById('muteSound') as HTMLMediaElement
    audio.muted = true;
}

html

               <button onclick="enableMute()" type="button">Mute sound</button>
<video id="muteSound" muted="true" playsinline autoplay loop preload="auto">
    <source src="assets/videos/louvre.mp4" type="video/mp4" >
</video>

In your .ts script, where do you toggle audio.muted? I only see code to set it to true. Where is false?

Also, if your script language support it the line of code could be audio.muted = not(audio.muted)
https://html.com/attributes/audio-muted/ shows the mini-player with the audio mute control showing without any added code.

The sound plays in autoplay when the page loads and i need a on/off button. I haven't created a on/off function

commented: Check out the link. I see a button in the control to mute/unmute. +15

Try to create thу on/off function and describe the results.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.