setSpeakerphoneOn method
enable set speakerphone on or off, by default wired/bluetooth headsets will still
be prioritized even if set to true.
forceSpeakerOutput if true, will force speaker output even if headphones
or bluetooth is connected, only supported on iOS for now
Implementation
Future<void> setSpeakerphoneOn(bool enable, {bool forceSpeakerOutput = false}) async {
if (canSwitchSpeakerphone) {
_preferSpeakerOutput = enable;
_forceSpeakerOutput = forceSpeakerOutput;
if (lkPlatformIs(PlatformType.iOS)) {
NativeAudioConfiguration? config;
if (lkPlatformIs(PlatformType.iOS)) {
// Only iOS for now...
config = await onConfigureNativeAudio.call(audioTrackState);
if (_preferSpeakerOutput && _forceSpeakerOutput) {
config = config.copyWith(
appleAudioCategoryOptions: {
AppleAudioCategoryOption.defaultToSpeaker,
},
);
}
logger.fine('configuring for ${audioTrackState} using ${config}...');
try {
if (_isAutomaticConfigurationEnabled) {
await Native.configureAudio(config);
}
} catch (error) {
logger.warning('failed to configure ${error}');
}
}
} else {
await rtc.Helper.setSpeakerphoneOn(enable);
}
} else {
logger.warning('setSpeakerphoneOn only support on iOS/Android');
}
}