1

I have an Electron application with React plugged for my view layer.

I want to be able to access audio input to my laptop. Audio input will be more than a microphone, I am wanting to input music into my laptop via USB as it doesn't have any audio input ports and ideally I want this to work on any laptop.

I have played around with the getUserMedia() api like so:

window.navigator.mediaDevices.getUserMedia(constraints)
      .then(stream => this.handleStream(stream))
      .catch(err => this.handleError(err))

but believe this is for accessing microphone? Is there a way you can select audio input and if so, will I be able to get an audio input from a USB device or is the getUserMedia API limited to microphones?

Stretch0
  • 8,362
  • 13
  • 71
  • 133
  • 1
    Microphone is a form of audio input. On most systems it's the only audio input configured. You enumerate audio input devices using [`navigator.mediaDevices.enumerateDevices`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices), then use [`deviceId`](https://stackoverflow.com/a/33770656/918910) to select a specific one. – jib May 23 '18 at 23:45
  • That seems to be what I was looking for. If you post your comment as an answer, I will mark complete. Thanks – Stretch0 May 24 '18 at 08:38

1 Answers1

3

Microphone is a form of audio input. On most systems it's the only audio input configured.

You enumerate audio input devices using navigator.mediaDevices.enumerateDevices, then use the deviceId constraint with getUserMedia to select a specific one.

jib
  • 40,579
  • 17
  • 100
  • 158
  • Hi @Stretch0 ! Can you confirm that `navigator.mediaDevices.enumerateDevices` can help `getUserMedia` access others audio input source (for example line-in audio from phone, CD player, mp3 player...) other than microphone as default? – trungkmy Sep 23 '21 at 04:07