Reputation: 1648
How can i mute the microphone via onclick function in javascript. im doing it like this
audio.js
function muteAudio(){
easyrtc.enableAudio(false);
}
livestreaming.html
<button type="button" id="muteButton" class="btn-cust btn-trans mutemic" title="Mic" >
<i class="material-icons" onclick = "muteAudio()">mic</i>
</button>
But this doesn't work. Can someone help me please.
Upvotes: 1
Views: 1936
Reputation: 199
I have been using easyrtc.enableMicrophone(true)
to switch between muting and not muting the microphone. I have it mapped to the spacebar to act as a push to talk.
Upvotes: 0
Reputation: 15293
.enableAudio()
will set whether to transmit audio or not. If you want to mute the local or remote media stream simply use the audio or video elements volume attribute to do that.
Here is an example.
var audio = document.querySelector('audio');
var button = document.querySelector('button');
audio.volume = 0.5;
button.addEventListener('click', function(e) {
audio.volume = (audio.volume === 0) ? .5 : 0;
this.textContent = (this.textContent === 'Mute Audio') ? 'Unmute Audio' : 'Mute Audio';
})
<audio src="https://upload.wikimedia.org/wikipedia/commons/4/41/Ascending_fifths.wav" autoplay loop>
Your browser does not support the <code>audio</code> element.
</audio>
<button>Mute Audio</button>
Upvotes: 1