switchToEarpiece method
Implementation
Future<bool> switchToEarpiece() async {
Log().info('switchToEarpiece');
final androidAudioManager =
!kIsWeb && Platform.isAndroid ? AndroidAudioManager() : null;
if (androidAudioManager != null) {
androidAudioManager.setMode(AndroidAudioHardwareMode.inCommunication);
androidAudioManager.stopBluetoothSco();
androidAudioManager.setBluetoothScoOn(false);
androidAudioManager.setSpeakerphoneOn(false);
_currentInput = AudioDevice(id: "Earpiece", name: "Earpiece",
isInput: false, isOutput: true,
type: AudioDeviceType.builtInEarpiece);
return true;
} else {
final avAudioSession = !kIsWeb && Platform.isIOS ? AVAudioSession() : null;
if (avAudioSession != null) {
Future.delayed(const Duration(milliseconds: 1), () async {
final result = await _switchToAnyIosPortIn(
{AVAudioSessionPort.builtInMic});
});
// if (result == true) {
// _currentInput = AudioDevice(id: "Earpiece", name: "Earpiece",
// isInput: false, isOutput: true,
// type: AudioDeviceType.builtInEarpiece);
// }
// return result;
_currentInput = AudioDevice(id: "Earpiece",
name: "Earpiece",
isInput: false,
isOutput: true,
type: AudioDeviceType.builtInEarpiece);
return true; // Always return true to avoid delay update ui
}
}
return false;
}