1

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.

Ginxxx
  • 1,602
  • 2
  • 25
  • 54

2 Answers2

1

.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>
DavidDomain
  • 14,976
  • 4
  • 42
  • 50
0

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.

Kyle Foley
  • 190
  • 7