Android Mobile Browser - navigator.mediaDevices.enumerateDevices method returns audio input and output device values swapped
Asked Answered
N

3

7

I am using the navigator function - navigator.mediaDevices.enumerateDevices() to get the list of media devices, in my mobile browser application. I am using the below code:

navigator.mediaDevices.enumerateDevices().then(function(devices) {
 console.log("devices", devices);
});

I am getting the audio input and audio output devices object values swapped as below:

[
  {
    "deviceId": "default",
    "kind": "audioinput",
    "label": "Default",
    "groupId": "41a111f571a1171ca91c5428d2ad8806a66bb6d7c5812f779161151a706641a1"
  },
  {
    "deviceId": "bbf2c347dbfc70b9e37b16be622c4973a74269c7f53d4162adab0c09614514d1",
    "kind": "audioinput",
    "label": "Speakerphone",
    "groupId": "e8dc20cc0a8dd33f65085c2f06bb8424105eb230c54237c343b8f8ff960559f3"
  },
  {
    "deviceId": "704cd1e8449390f5bb3fd1615a7637753f4ad019d4e6bb3f7c36690f58f2536d",
    "kind": "audioinput",
    "label": "Headset earpiece",
    "groupId": "1f2f370cbbe3f57fe3a8e901dc8f82c8d751f690520c261b293b1480e7959218"
  },
  {
    "deviceId": "38f008a97b8fd5ff8d367c336fcb7120fdc499375fb44459980d60395516b955",
    "kind": "videoinput",
    "label": "camera2 1, facing front",
    "groupId": "3b073bb17b0c56c5f8e6f143d6eeebcbfac5ec2ebc8ff2bc852f66745a63c591"
  },
  {
    "deviceId": "bbf2c347dbfc70b9e37b16be622c4973a74269c7f53d4162adab0c09614514d1",
    "kind": "videoinput",
    "label": "camera2 0, facing back",
    "groupId": "5a8b08633d9b089d234fc7bb0d67fae394e90a4f7948128562251d17408d99d4"
  },
  {
    "deviceId": "default",
    "kind": "audiooutput",
    "label": "Default",
    "groupId": "default"
  }
]

I have tried this in three other android mobile browsers and it's swapping the values in those devices also. In PC it's working correctly. Why it's swapping those values in mobile browsers?

Also, I have checked this webpage to verify - webrtc input-output devices, here it's showing speakerphone in audio input devices list as you can see in the screenshot below.

enter image description here

Noli answered 2/4, 2020 at 14:35 Comment(4)
I've noticed this behavior as well on 5 different android phones. enumerateDevices() swaps audioinput and audiooutput devices. Did you ever find a reason for this behavior or got confirmation if it's a bug?Hurlee
No. Didn't get any reason yet.Noli
I still see this issue, perhaps a chrome bug should be filed?Eufemiaeugen
Could you find out why Speakerphone and Headset earpiece appear as audioInput devices?Shapeless
C
1

Might have to do with the fact that you can't set the sinkId on HTML Elements on Android devices (https://caniuse.com/?search=setsinkid). And, I assume that in your case, the Speakerphone refers to the system default audio (including the internal system speakerphone and associated mic) and that your headset has a microphone also and hence also shows up as an input. So, in that case, seems you need to get user media again with the speakerphone device which will result in the input coming from the internal mic but seems that the output also gets set to the speakerphone output.

On a separate note, why the groupId for the default is not the same as the actual groupId of the separately listed device is a hassle because not so easy to figure out which of the devices the default actually is.

Cheung answered 9/3, 2023 at 6:31 Comment(0)
F
0

I know this is old, but I have the same problem, newsets Chrome, Android 12. I have tested with https://webrtc.github.io/samples/src/content/devices/input-output/ and in Chrome audio inputs are listed as outputs and outputs as inputs. So I get as input:

  • Standard
  • Speakerphone
  • Headset earpiece

As output I get:

  • Standard

On the same phone in FireFox it works OK. Of course, I cannot choose output as FF does not support it, but the input just lists Standard, as it should.

Faretheewell answered 19/8, 2022 at 15:52 Comment(2)
I'm also struggling with this. I can switch a webrtc call from default (speakerphone) to "headset earpiece" - but never back again.Bejewel
@JamesHarcourt How can you do this is mobile devices?? because it is not supported on mobile devicesVocational
E
0

This is a bug with Android: https://bugs.chromium.org/p/chromium/issues/detail?id=1255478#c11

I reported it and have been providing feedback to the Google team, but they don't seem to be actively fixing it.

Eufemiaeugen answered 27/11, 2023 at 21:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.