6

I stream audio over rtc and want to mute and unmute the audio.

This works... but no gain control:

function(stream) { /* getUserMedia stream */
      console.log("Access granted to audio/video");
      peer_connection.addStream(stream);
}

This works on chrome but NOT on Firefox (with gain control)

function(stream) { /* getUserMedia stream */
  console.log("Access granted to audio/video");
  var microphone = context.createMediaStreamSource(stream);
  gainNode = context.createGain();
  var dest = context.createMediaStreamDestination();
  microphone.connect(gainNode);
  gainNode.connect(dest);

  local_media_stream = dest.stream;
  peer_connection.addStream(local_media_stream);
}

I get no error and i hear no voice. When I send the gainNode to context.destination i can hear myself.

I think "context.createMediaStreamSource(stream)" is broken in any way. Can anyone tell me why ? and how to fix this.


EDIT: So i checked the streams and:

stream //type: LocalMediaStream    
dest.steam //type: MediaStream

in Firefox! In chrome both are MediaStreams

Cracker0dks
  • 2,422
  • 1
  • 24
  • 39
  • What do FF return if you use `navigator.mediaDevices.getUserMedia` instead of `navigator.getUserMedia`? –  Apr 14 '15 at 21:47
  • 1
    the same data types and the same result: no voice. But worth a try :) – Cracker0dks Apr 14 '15 at 22:02
  • Yeah, they probably just made that available and wired up the same code as with the old way. –  Apr 14 '15 at 22:09

2 Answers2

3

To mute the audio you can enable/disable the track itself by doing:

stream.getAudioTracks()[0].enabled = false;  // mutes

This won't solve the problem with the gain node, which is most likely a bug/limitation in Firefox at the moment (in which case we can only wait for a fix). But if the purpose is to (un)mute this should work (it also works with video tracks).

  • Sadly this inst working because type of stream is : LocalMediaStream and not MediaStream as in chrome. So it dont have the getAudioTracks() function. In chrome this works perfectly! – Cracker0dks Apr 14 '15 at 21:41
  • 1
    but smart way to mute :) – Cracker0dks Apr 14 '15 at 22:09
  • 1
    @Cracker0dks it makes it simple :) Nightly will probably take a few months but at least it's in the works –  Apr 14 '15 at 22:10
3

Ok thanks to @Ken Fyrstenberg I just tried the Firefox Nighly build. On the Nighly everythink works fine (as in Chrome). The data types are:

stream //type: LocalMediaStream    
dest.steam //type: MediaStream

as before, but I can hear the opponent and be able to mute the mic.

So I only have to wait for release :P

Cracker0dks
  • 2,422
  • 1
  • 24
  • 39