Could not start audio source error on mediaDevices.getUserMedia

Viewed 452

I am trying to make a screen recorder with electron.js

I have used desktopCapturer.getSources to get all the screens which is working fine but when I am tring to get stream using navigator.mediaDevices.getUserMedia it throws a error :

> DOMException: Error could not start audio source
const handleRecordActions = async () => {
    const { id } = activeScreen;
    try {
      // console.log("here", navigator);
      stream = await navigator.mediaDevices.getUserMedia({
        audio: {
          mandatory: {
            chromeMediaSource: "desktop",
            chromeMediaSourceId: id,
          },
        },
        video: {
          mandatory: {
            chromeMediaSource: "desktop",
            chromeMediaSourceId: id,
          },
        },
      });
      stream.stop = function () {
        stream.getAudioTracks().forEach(function (track) {
          track.stop();
        });
        stream.getVideoTracks().forEach(function (track) {
          //in case... :)
          track.stop();
        });
      };
      setStream(stream);
      handleStream(stream);

      // console.log({ stream, d: stream.getAudioTracks() });
    } catch (e) {
      console.log(e);
    }
  };

If I make audio: false then it throws different error :

> DOMException: Error starting screen capture

I am working on :

Ubuntu : 20.04
Electron : ^16.0.4

Edit :

I have confirmed that this error is occurring in linux (Ubuntu) only as the same code is working seamlessly in windows.

0 Answers
Related