8000 fix: :bug: Fixed the problem that iOS earphones and speakers do not s… · withub-com/flutter-webrtc@21ec10d · GitHub
[go: up one dir, main page]

Skip to content

Commit 21ec10d

Browse files
authored
fix: 🐛 Fixed the problem that iOS earphones and speakers do not switch (flutter-webrtc#1147)
1 parent 145b79c commit 21ec10d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

common/darwin/Classes/AudioUtils.m

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,28 @@ + (void)setSpeakerphoneOn:(BOOL)enable {
6767
[session lockForConfiguration];
6868
NSError *error = nil;
6969
if(!enable) {
70-
[session setCategory:config.category
71-
withOptions:config.categoryOptions
72-
error:&error];
7370
[session setMode:config.mode error:&error];
74-
BOOL success = [session setActive:YES error:&error];
71+
BOOL success = [session setCategory:config.category
72+
withOptions:AVAudioSessionCategoryOptionAllowAirPlay|AVAudioSessionCategoryOptionAllowBluetoothA2DP|AVAudioSessionCategoryOptionAllowBluetooth
73+
error:&error];
74+
75+
success = [session.session overrideOutputAudioPort:kAudioSessionOverrideAudioRoute_None error:&error];
76+
if (!success) NSLog(@"Port override failed due to: %@", error);
77+
78+
success = [session setActive:YES error:&error];
7579
if (!success) NSLog(@"Audio session override failed: %@", error);
7680
else NSLog(@"AudioSession override via Earpiece/Headset is successful ");
81+
82+
7783
} else {
84+
[session setMode:config.mode error:&error];
7885
BOOL success = [session setCategory:config.category
79-
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
86+
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowAirPlay|AVAudioSessionCategoryOptionAllowBluetoothA2DP|AVAudioSessionCategoryOptionAllowBluetooth
8087
error:&error];
81-
[session setMode:config.mode error:&error];
88+
89+
success = [session overrideOutputAudioPort:kAudioSessionOverrideAudioRoute_Speaker error:&error];
8290
if (!success) NSLog(@"Port override failed due to: %@", error);
91+
8392
success = [session setActive:YES error:&error];
8493
if (!success) NSLog(@"Audio session override failed: %@", error);
8594
else NSLog(@"AudioSession override via Loudspeaker is successful ");

0 commit comments

Comments
 (0)
0