Skip to content

Desktop audio capture does not work on Mac and Linux #10515

Closed

Description

@mhashmi
  • Electron version: 1.6.2, 1.6.5, 1.7.6, 2.0.2, 3.x, 4.0.5
  • Operating system: Mac OS X Sierra, Linux (Debian Jessie)

Expected behavior

Given the defined DesktopCapture API for capturing both audio and video for the entire desktop, we should get a working audio stream on Windows, Linux and Mac.

Actual behaviour

Electron version 4.0.5: On Mac and Linux, the error callback triggers with the respective messages:

getUserMediaError:  DOMException: Could not start audio source // Mac
Failed to query stereo recording // Linux

Electron Version 1.7.6: On Mac and Linux, the error callback triggers with the error:

NavigatorUserMediaError
    constraintName: ""
    message: ""
    name: "TrackStartError"

Electron Version 1.6.2 and 1.6.5: On Mac and Linux, the video stream is received successfully, albeit, with no audio.

Below are the constraints defined as per the DesktopCapture API:

const constraints = {
  audio: {
    mandatory: {
      chromeMediaSource: 'desktop'
    }
  },
  video: {
    mandatory: {
      chromeMediaSource: 'desktop'
    }
  }
}

Please note: on Windows, the audio capture works correctly.

How to reproduce

git clone https://github.com/mhashmi/electron-desktop-capture
cd electron-desktop-capture
npm install
npm start

Activity

  1. welcome commented on Sep 14, 2017

    @welcome

    👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

    To help make it easier for us to investigate your issue, please follow the contributing guidelines.

  2. jordanbaucke commented on Nov 8, 2017

    @jordanbaucke

    +1 - confirmed on Electron V 1.7.9

  3. MarshallOfSound commented on Nov 8, 2017

    @MarshallOfSound
    Member

    @jasonrudolph Please use GH reactions instead of adding a "+1" comment.

  4. MarshallOfSound commented on Nov 8, 2017

    @MarshallOfSound
    Member

    GH reaction == GitHub reaction, you used one just now to thumbs down my comment asking you to use them 🤔

  5. jordanbaucke commented on Nov 8, 2017

    @jordanbaucke

    @MarshallOfSound which emoji should I use for confirming the version? since we're getting specific.

  6. MarshallOfSound commented on Nov 8, 2017

    @MarshallOfSound
    Member

    Your initial comment did not contain a version number and therefore could have simply been replaced with a thumbs up on the original issue

  7. jasonrudolph commented on Nov 8, 2017

    @jasonrudolph

    @jasonrudolph Please use GH reactions instead of adding a "+1" comment.

    @MarshallOfSound: As someone that got a notification from you for a thread I'm not even participating in, is it helpful for me to say, "Please make sure you're @mentioning the right person."??? 😜

  8. MarshallOfSound commented on Nov 9, 2017

    @MarshallOfSound
    Member

    Haha, sorry Jason. Been doing this from my phone and didn't check the at mention, my bad 😸

  9. roy2651 commented on Mar 8, 2018

    @roy2651

    how to fix it

  10. 64 remaining items

  11. cybe42 commented on Mar 26, 2022

    @cybe42

    The same issue is still in Linux. Please reopen.

  12. Spark61 commented on Apr 3, 2022

    @Spark61

    I have also the same issue

  13. weedsboy commented on Jun 7, 2022

    @weedsboy

    same issue on linux

    ubuntu 22.04
    electron 9.4.0

  14. sniff122 commented on Jun 21, 2022

    @sniff122

    ngl this is one of the many reasons why i dont like electron, this issue has existed since september 2017, was fixed for mac and basically ignored for linux, absolutely terrible. This issue is not resolved so it shouldnt have been closed

  15. ApeironTsuka commented on Jun 21, 2022

    @ApeironTsuka

    ngl this is one of the many reasons why i dont like electron, this issue has existed since september 2017, was fixed for mac and basically ignored for linux, absolutely terrible. This issue is not resolved so it shouldnt have been closed

    @sniff122
    To be fair to Electron, this issue is blocked by Chromium itself. And they don't seem to be in a hurry to ever fix it. It should theoretically be possible for Electron to roll their own fix in, but that's largely outside the scope of the project.

    A kludgy sort of "fix" (at least for PulseAudio-based systems) would be to expose a virtual sink when capturing and leave it as an exercise for the user to get the application/system audio into it (likely via a combination of module-loopback and module-combine-sink), but that's very user-unfriendly.

  16. mattia-moffa commented on Jun 22, 2022

    @mattia-moffa

    The idea of exposing a virtual sink the user can bind their application to is still light years better than nothing. At least the audio can be shared in some way.

  17. Hrishabh17 commented on Apr 7, 2023

    @Hrishabh17

    I also had the problem in Ubuntu (video with audio stream of a BrowserWindow) and solved it in our app with the help of "paclient" (https://github.com/mscdex/paclient).

    // Move  the  specified  recording  stream  (identified by its numerical index) 
    // to the specified source (identified by its symbolic name or numerical index).
    // e.g. "pacmd move-source-output ID alsa_output.pci-0000_02_02.0.analog-stereo.monitor"
    

    Then the corresponding deviceId can be used in the audio constraints and mixed with the video stream to get a video-with-audio stream. But a simpler solution would of course be better.

    @AmarBouchibane Hi, I am also stuck with the system audio not recording in Linux, could you show me how you achieved it? Like where have you added this code? Thank you, it's really urgent.

  18. mehdignu commented on Aug 16, 2023

    @mehdignu

    Is this fixed? I still have the same error.

  19. Hrishabh17 commented on Aug 16, 2023

    @Hrishabh17

    Is this fixed? I still have the same error.

    Yes, for Linux I used pulse audio to redirect the system audio to my application and thence use it. If you need the command to create the virtual sink and source I can share it. You can execute the command in the pre-loader of the electron app. For mac, there is an alternative (sound flower). I was mostly concerned with linux and windows so never bothered about mac.

  20. KonstantinBel commented on Sep 14, 2023

    @KonstantinBel

    Is this fixed? I still have the same error.

    Yes, for Linux I used pulse audio to redirect the system audio to my application and thence use it. If you need the command to create the virtual sink and source I can share it. You can execute the command in the pre-loader of the electron app. For mac, there is an alternative (sound flower). I was mostly concerned with linux and windows so never bothered about mac.

    I'd like to see your solution, I have the same problem, but don't have an experience with Linux to understand how to use PulsAudio.

  21. kerberizer commented on Sep 14, 2023

    @kerberizer

    Some possibly good news. Apparently, work on the upstream issue in Chromium has started on Aug 18, 2023.

  22. Hrishabh17 commented on Sep 15, 2023

    @Hrishabh17

    Is this fixed? I still have the same error.

    Yes, for Linux I used pulse audio to redirect the system audio to my application and thence use it. If you need the command to create the virtual sink and source I can share it. You can execute the command in the pre-loader of the electron app. For mac, there is an alternative (sound flower). I was mostly concerned with linux and windows so never bothered about mac.

    I'd like to see your solution, I have the same problem, but don't have an experience with Linux to understand how to use PulsAudio.

    sure, what I did is:

    I used spawn to run the commands as follow:


    Step 1:

    const monitorProcess = spawn('pacmd list-sources | grep -B 1 analog-stereo.monitor | grep name:', {
    shell: true
    });

    this actually checks if there is already a monitor or not (simple way we need to create this monitor if its not present, there is one default monitor but its of no use, so to route the system audio we need to create this, I'll reference it as user monitor hence forth to explain other steps"


    Step 2:

    monitorProcess.stdout.on('data', function (data) {
    const output = data.toString();
    const l = output.split('\n')
    if(l.length <= 2){
    const regex = /name:\s*<(.+)>/i;
    const match = output.match(regex);
    let monitorName
    if (match && match.length > 1) {
    monitorName = match[1];
    }
    const moduleGenerate = spawn(pactl load-module module-remap-source master=${monitorName} source_properties=device.description=Computer-sound, {
    shell:true
    })
    moduleGenerate.stdout.on('end', ()=>{
    })
    }
    });

    This simply checks the if the user monitor already created (monitors refresh/reset after a system restart, if its already present then no need to create it). (to get more idea about this simply run the commands in step1 followed by step2 and find it your self, do it for 5-6 times and you will be comfortable with what we are doing)


    Step 3:

    Once the monitor is created, we can use this in the frontend (webRTC call) and it will be listed as one of the sources. This source will acts a way to get the system audio.


    Step 4:

    Once this is done, you can take the microphone audio source as well (two webRTC calls) then you'll have to combine these two sources (if you need help regarding this I would be happy to help, this too can be done with vanilla javascript without any packages)

  23. GitHubCloud commented on Mar 6, 2024

    @GitHubCloud

    I've recently had this issue on Mac, though I'm a little bit late in the comments, I have to say I bypassed it using Sound flower. Here is a detailed blog post about my solution: This include every code snippet to record system audio on MacOS and even video and then combine both streams to make audio and video together.

    I know it's been quite a time, but were you able to build a package with the SoundFlower solution?

  24. benkingcode commented on May 3, 2024

    @benkingcode

    Chromium has apparently fixed this now: https://issues.chromium.org/issues/40155218

    Will Electron be gaining this functionality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions