selectPreferHeadphone method

void selectPreferHeadphone()

Implementation

void selectPreferHeadphone() async {
  final audioOutput = await Helper.audiooutputs;
  final preferBluetooth =
      audioOutput.where((item) => item.deviceId == 'bluetooth');
  if (preferBluetooth.isNotEmpty) {
    Helper.selectAudioOutput('bluetooth');
    Helper.selectAudioInput("bluetooth");
    _audioSelected = 'bluetooth';
    return;
  }
  final preferWiredHeadset =
      audioOutput.where((item) => item.deviceId == 'wired-headset');
  if (preferWiredHeadset.isNotEmpty) {
    Helper.selectAudioOutput('wired-headset');
    Helper.selectAudioInput("wired-headset");
    _audioSelected = 'wired-headset';
    return;
  }

  final devices = await navigator.mediaDevices.enumerateDevices();
  final audioInput =
      devices.where((device) => device.kind == 'audioinput').toList();

  final preferMicro =
      audioInput.where((item) => item.deviceId == 'microphone-bottom');

  if (preferMicro.isNotEmpty) {
    Helper.selectAudioInput("microphone-bottom");
  } else {
    Helper.setSpeakerphoneOn(false);
  }

  Helper.selectAudioOutput('earpiece');
  _audioSelected = 'earpiece';
}