Search code examples
javascriptangularionic-frameworkhtml5-audio

My ear speaker doesn't detected in my Angular app (using enumerateDevices)


I am building a project with Ionic 5 / Angular. I want to build a voice call app, which needs to access my phone ear speaker, not the loudspeaker.

The problem is when I fetch my device's audio output using enumerateDevices(), I don't find any other audio output besides the default audio output (the loudspeaker itself).

IO Devices

I want to attach the HTMLMediaElement using .setSinkId() to the ear speaker's device ID, but didn't find it. Is there any native plugin or workaround for this? Or is it just my phone that doesn't support it? Currently, I am using Samsung Galaxy A51.

Thank you.


Solution

  • Check this Plugin: Github Repo

    NPM : Npm LInk

    Usage:

    AudioToggle.setAudioMode(AudioToggle.SPEAKER);
    // or
    AudioToggle.setAudioMode(AudioToggle.EARPIECE);