-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[video_player_avfoundation, camera_avfoundation] never overwrite but only upgrade audio session category #7143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
787f41c
ef43db2
94a80df
f637396
86922ac
6746391
42bd00a
fde86f6
2f876dd
4ddc291
81a9449
4dd42c1
e02355c
6569354
1086400
9edbeef
6216653
59a7fab
8f013b6
acaad4c
3d4e638
948937e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1322,32 +1322,28 @@ - (BOOL)setupWriterForPath:(NSString *)path { | |
| // which depend on this global state, only change category or options if there is | ||
| // change to prevent unnecessary lags and silence | ||
| // https://github.com/flutter/flutter/issues/131553 | ||
|
||
| static void upgradeAudioSessionCategory(AVAudioSessionCategory category, | ||
| AVAudioSessionCategoryOptions options, | ||
| AVAudioSessionCategoryOptions clearOptions) { | ||
| if (category == nil) { | ||
| category = AVAudioSession.sharedInstance.category; | ||
| } | ||
| static void upgradeAudioSessionCategory(AVAudioSessionCategory requestedCategory, | ||
| AVAudioSessionCategoryOptions options) { | ||
| NSSet *playCategories = [NSSet | ||
| setWithObjects:AVAudioSessionCategoryPlayback, AVAudioSessionCategoryPlayAndRecord, nil]; | ||
| NSSet *recordCategories = | ||
| [NSSet setWithObjects:AVAudioSessionCategoryRecord, AVAudioSessionCategoryPlayAndRecord, nil]; | ||
| NSSet *categories = [NSSet setWithObjects:category, AVAudioSession.sharedInstance.category, nil]; | ||
| BOOL needPlay = [categories intersectsSet:playCategories]; | ||
| BOOL needRecord = [categories intersectsSet:recordCategories]; | ||
| NSSet *requiredCategories = [NSSet setWithObjects:requestedCategory, AVAudioSession.sharedInstance.category, nil]; | ||
| BOOL needPlay = [requiredCategories intersectsSet:playCategories]; | ||
|
||
| BOOL needRecord = [requiredCategories intersectsSet:recordCategories]; | ||
| if (needPlay && needRecord) { | ||
| category = AVAudioSessionCategoryPlayAndRecord; | ||
| requestedCategory = AVAudioSessionCategoryPlayAndRecord; | ||
| } else if (needPlay) { | ||
| category = AVAudioSessionCategoryPlayback; | ||
| requestedCategory = AVAudioSessionCategoryPlayback; | ||
| } else if (needRecord) { | ||
| category = AVAudioSessionCategoryRecord; | ||
| requestedCategory = AVAudioSessionCategoryRecord; | ||
| } | ||
| options = (AVAudioSession.sharedInstance.categoryOptions & ~clearOptions) | options; | ||
| if ([category isEqualToString:AVAudioSession.sharedInstance.category] && | ||
| options = AVAudioSession.sharedInstance.categoryOptions | options; | ||
| if ([requestedCategory isEqualToString:AVAudioSession.sharedInstance.category] && | ||
| options == AVAudioSession.sharedInstance.categoryOptions) { | ||
| return; | ||
| } | ||
| [AVAudioSession.sharedInstance setCategory:category withOptions:options error:nil]; | ||
| [AVAudioSession.sharedInstance setCategory:requestedCategory withOptions:options error:nil]; | ||
| } | ||
|
|
||
| - (void)setUpCaptureSessionForAudioIfNeeded { | ||
|
|
@@ -1369,11 +1365,11 @@ - (void)setUpCaptureSessionForAudioIfNeeded { | |
| _audioOutput = [[AVCaptureAudioDataOutput alloc] init]; | ||
|
|
||
| dispatch_block_t block = ^{ | ||
| // Setup options implicit to AVAudioSessionCategoryPlayback to not disturb video_player. | ||
|
||
| upgradeAudioSessionCategory(AVAudioSessionCategoryPlayAndRecord, | ||
| AVAudioSessionCategoryOptionDefaultToSpeaker | | ||
| AVAudioSessionCategoryOptionAllowBluetoothA2DP | | ||
| AVAudioSessionCategoryOptionAllowAirPlay, | ||
| 0); | ||
| AVAudioSessionCategoryOptionAllowAirPlay); | ||
| }; | ||
| if (!NSThread.isMainThread) { | ||
| dispatch_sync(dispatch_get_main_queue(), block); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me how this last part is different from what the comment already said so far (possibly because the sentence is a run-on by this point so it's hard to follow). Please reword to clarify if this is supposed to be adding new details.