title: WebRTC - How to mute local audio output
body: <p>I'm trying to mute only the local audio playback in WebRTC, more specifically after getUserMedia() and prior to any server connection being made. None of the options I've found work; this one from Muaz Khan fails:</p>
  
  <pre><code>var audioTracks = localMediaStream.getAudioTracks();
  // if MediaStream has reference to microphone
  if (audioTracks[0]) {
      audioTracks[0].enabled = false;
  }
  </code></pre>
  
  <p><a href="http://muaz-khan.blogspot.com/2014/05/webrtc-tips-tricks.html" rel="noreferrer">source</a></p>
  
  <p>This technique is also <a href="https://code.google.com/p/chromium/issues/detail?id=114163" rel="noreferrer">described here</a> as "working", but fails here on Chrome Version 39.0.2171.95 (64-bit) (Ubuntu 14.04).</p>
  
  <p>Additional method that is said to work by using volume gain:</p>
  
  <pre><code>window.AudioContext = window.AudioContext || window.webkitAudioContext;
  var audioContext = new AudioContext();
  var source = audioContext.createMediaStreamSource(clientStream);
  var volume = audioContext.createGain();
  source.connect(volume);
  volume.connect(audioContext.destination);
  volume.gain.value = 0;  //turn off the speakers
  </code></pre>
  
  <p>tl;dr I don't want to hear the input from my microphone on my speakers, but I do want to see my video image.</p>
  
  <p><strong>Workaround</strong></p>
  
  <p>This workaround was suggested by <a href="https://stackoverflow.com/users/1818849/benjamin-trent">Benjamin Trent</a> and it mutes the audio by setting the muted attribute on the video tag like so:</p>
  
  <pre><code>document.getElementById("html5vid").muted = true;
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/20804667/webrtc-getusermedia-how-to-properly-mute-local-video">Also similar question, but its for video, so not the same</a></p>