2

I am trying to build a chrome extension that captures a users screen with their speaker audio (computer audio) and their microphone audio. Using the examples from RecordRTC I have pieced the below together, however when I open the recorded .webm file I am unable to hear any sounds at all.

Is there something else I should be doing to get audio?

Below is the code for my background script with some sections removed to make it more clear. When someone clicks the start record button, the startRecording() function is called.

const OPTIONS = {
  type: 'video',
  disableLogs: false,
  mimeType: 'video/webm'
}

const captureUserMedia = callback => {
  chrome.desktopCapture.chooseDesktopMedia(['screen', 'window', 'audio'], chromeMediaSourceId => {
    const options = {
      audio: {
        mandatory: {
          chromeMediaSource: 'desktop',
          chromeMediaSourceId: chromeMediaSourceId,
          echoCancellation: true
        },
        optional: []
      },
      video: {
        mandatory: {
          chromeMediaSource: 'desktop',
          chromeMediaSourceId: chromeMediaSourceId
        },
        optional: []
      }
    };
    navigator.mediaDevices.getUserMedia(options)
      .then(callback)
      .catch(err => new Error(err));
    });
};

const startRecording = () => {
  captureUserMedia(mediaStream => {
    state.recordData = RecordRTC(mediaStream, OPTIONS);
    state.mediaStream = mediaStream;
    state.recordData.startRecording();
  });
}

const stopRecording = () => {
  state.recordData.stopRecording(function(videoURL) {
    chrome.tabs.create({ url: 'show-video.html?video=' + videoURL });
  });
  state.mediaStream.getTracks().forEach(track => track.stop());
}
Matt Hough
  • 1,049
  • 2
  • 13
  • 27
  • Try looking into this tutorials/guide for capturing audio using Chrome extension: [Chrome-Audio-Capturer](https://github.com/arblast/Chrome-Audio-Capturer), [Introducing getUserMedia and the Javascript Gamepad API](https://blog.chromium.org/2012/07/introducing-getusermedia-and-javascript.html). They use [`chrome.tabCapture`](https://developer.chrome.com/extensions/tabCapture) which has a Capture option for audio and video. Hope this helps. – Mr.Rebot Apr 30 '18 at 16:29
  • 1
    @Mr.Rebot - I wonder if the audio capabilities of `tabCapture` are about capturing audio *output* rather than input (i.e. mic). This is certainly the case with `desktopCapture`; I made the mistake of thinking that, when it said audio, it meant I could record screen + mic at the same time. Turns out it meant system sounds. To record mic as well I had to run a separate `mediaStream` on mic audio, then glue the two streams together via `addTrack()`. – Mitya Jun 26 '18 at 12:15
  • [My own related issue](https://stackoverflow.com/questions/51042895/chrome-desktopcapture-cant-recrod-both-system-audio-and-microphone) – Mitya Jun 26 '18 at 12:26
  • @all, Does speaker capture working for Window? or just only for tab and whole desktop. For me speaker capture for a window is not working. – Sasi Varunan Nov 14 '18 at 14:51

1 Answers1

1

Apparently this is not a bug and an issue with MacOS itself. Chrome are aware of it but don't seem to have any plans to fix it: bugs.chromium.org/issue/603259

Matt Hough
  • 1,049
  • 2
  • 13
  • 27