File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,13 @@ - (instancetype)initWithChannel:(FlutterMethodChannel *)channel
75
75
self.localTracks = [NSMutableDictionary new ];
76
76
self.renders = [[NSMutableDictionary alloc ] init ];
77
77
#if TARGET_OS_IPHONE
78
- [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (didSessionRouteChange: ) name: AVAudioSessionRouteChangeNotification object: nil ];
78
+ AVAudioSession *session = [AVAudioSession sharedInstance ];
79
+ [session setCategory: AVAudioSessionCategoryMultiRoute withOptions: AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers error: nil ];
80
+ [session setActive: YES withOptions: kAudioSessionSetActiveFlag_NotifyOthersOnDeactivation error: nil ];
81
+
82
+ [session setActive: YES error: nil ];
83
+
84
+ [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (didSessionRouteChange: ) name: AVAudioSessionRouteChangeNotification object: session];
79
85
#endif
80
86
return self;
81
87
}
@@ -88,6 +94,16 @@ - (void)didSessionRouteChange:(NSNotification *)notification {
88
94
89
95
switch (routeChangeReason) {
90
96
case AVAudioSessionRouteChangeReasonCategoryChange: {
97
+ AVAudioSession *session = [AVAudioSession sharedInstance ];
98
+ if ([session category ] != AVAudioSessionCategoryMultiRoute) {
99
+ NSError * setCategoryError;
100
+ [session setCategory: AVAudioSessionCategoryMultiRoute withOptions: AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers
101
+ error: &setCategoryError];
102
+ if (setCategoryError != nil ) {
103
+ NSLog (@" setCategoryError: %@ " , setCategoryError);
104
+ }
105
+ }
106
+
91
107
NSError * error;
92
108
[[AVAudioSession sharedInstance ] overrideOutputAudioPort: _speakerOn? AVAudioSessionPortOverrideSpeaker : AVAudioSessionPortOverrideNone error: &error];
93
109
}
You can’t perform that action at this time.
0 commit comments