I have a sound in my Angular project, like this:
introInfo() {
this.audio.src = '../assets/sound1.wav';
this.audio.load();
this.audio.play();
}
feedbackInfo() {
this.audio.src = '../assets/sound1.wav';
this.audio.load();
// auto-start
this.audio.play();
}
And I would like to be able to mute all sounds. If I click the button in my template:
<img class="grow" id="mute" [src]='mute' (click)="muteF()"/>
How could I write my function muteF
? I would like to mute if I click the button. If I click a second time, it must perform unmute.
This works for me
muteF() {
if (this.audio.volume !== 0) {
this.audio.volume = 0;
} else {
this.audio.volume = 1;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With