Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to record audio + screen due to error ScreenCaptureError #8589

Closed
siman opened this issue Feb 4, 2017 · 8 comments

Comments

@siman
Copy link

commented Feb 4, 2017

  • Electron version: electron 1.5.0
  • Operating system: Ubuntu 14.04.3 LTS

Expected behavior

Successfully recorded video of a screen + audio.

Actual behavior

In handleUserMediaError I receive an error:

NavigatorUserMediaError {name: "ScreenCaptureError", message: "", constraintName: ""}

How to reproduce

My code when trying to record video + audio.
I follow instructions from the documentation for webkitGetUserMedia:

To capture both audio and video from the entire desktop the constraints passed
to [navigator.webkitGetUserMedia] must include chromeMediaSource: 'screen',
and audio: true, but should not include a chromeMediaSourceId constraint.

navigator.webkitGetUserMedia({
  audio: true,
  video: {
    mandatory: {
      chromeMediaSource: 'screen',
      minWidth: 1280,
      minHeight: 720,
    }
  }
}, handleStream, handleUserMediaError);
@askucher

This comment has been minimized.

Copy link

commented Feb 4, 2017

+1 for mac as well

I cannot record a microphone speech

@groundwater

This comment has been minimized.

Copy link
Member

commented Feb 6, 2017

Thanks for the report @siman, I have verified on Ubuntu 16.04 as well.

@siman

This comment has been minimized.

Copy link
Author

commented Feb 6, 2017

@groundwater is electron's recording of audio supposed to record only webpage's sound, but not the mic?

@askucher

This comment has been minimized.

Copy link

commented Feb 6, 2017

@siman Please try

sudo apt-get install alsa-utils
@siman

This comment has been minimized.

Copy link
Author

commented Feb 10, 2017

I have found a solution. Read here: muaz-khan/RecordRTC#181

Here is a code that starts to record video+audio in Electron:

let recorder;
let blobs = [];

function captureScreenVideoWithAudio() {
  navigator.webkitGetUserMedia({
    audio: true
  }, function(audioStream) {
    navigator.webkitGetUserMedia({
      audio: false,
      video: {
        mandatory: {
          chromeMediaSource: 'screen',
          minWidth: 1280,
          minHeight: 720
        }
      }
    }, handleVideoStream(audioStream), handleUserMediaError);
  }, function() {});
}

function handleVideoStream(audioStream) {
  return function(videoStream) {
    if (audioStream) {
      let audioTracks = audioStream.getAudioTracks();
      if (audioTracks.length > 0) {
        videoStream.addTrack(audioTracks[0]);
      }
    }
    recorder = new MediaRecorder(videoStream);
    blobs = [];
    recorder.ondataavailable = function(event) {
      blobs.push(event.data);
    };
    recorder.start();
  };
}

function handleUserMediaError(e) {
  console.error('handleUserMediaError', e);
}
@kevinsawicki

This comment has been minimized.

Copy link
Contributor

commented Feb 21, 2017

I have found a solution.

Great thanks for the updates, closing this out 👍

@CapOM

This comment has been minimized.

Copy link
Contributor

commented Feb 21, 2018

Does it work to stream system audio ? (so not from the microphone but from anything that goes to default output)

@DamienDoumer

This comment has been minimized.

Copy link

commented Sep 30, 2019

though the above solution makes it possible to record microphone sound and mix it to the video stream, It does not permit you to get System Sound on MacOS. I resolved this issue using Soundflower and a modified the code above to accomplish what I wanted. In case anybody wants a solution to record system audio and video on MacOS, here is a detailed blog post about accomplishing this:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.