-
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 |
|---|---|---|
|
|
@@ -1223,7 +1223,7 @@ - (BOOL)setupWriterForPath:(NSString *)path { | |
| return NO; | ||
| } | ||
|
|
||
| [self setUpCaptureSessionForAudio]; | ||
| [self setUpCaptureSessionForAudioIfNeeded]; | ||
|
|
||
| _videoWriter = [[AVAssetWriter alloc] initWithURL:outputURL | ||
| fileType:AVFileTypeMPEG4 | ||
|
|
@@ -1303,22 +1303,17 @@ - (BOOL)setupWriterForPath:(NSString *)path { | |
| return YES; | ||
| } | ||
|
|
||
| // this same function is also in video_player_avfoundation | ||
| // configure application wide audio session manually to prevent overwriting | ||
| // flag MixWithOthers by capture session, only change category if it is considered | ||
| // as upgrade which means it can only enable ability to play in silent mode or | ||
|
||
| // ability to record audio but never disables it, that could affect other plugins | ||
|
||
| // which depend on this global state, only change category or options if there is | ||
| // change to prevent unnecessary route changes which can cause lags | ||
| // change to prevent unnecessary lags and silence | ||
|
||
| // https://github.com/flutter/flutter/issues/131553 | ||
|
||
| static void upgradeAudioSessionCategory(AVAudioSessionCategory category, | ||
| AVAudioSessionCategoryOptions options, | ||
| AVAudioSessionCategoryOptions clearOptions) { | ||
| if (!NSThread.isMainThread) { | ||
| dispatch_sync(dispatch_get_main_queue(), ^{ | ||
| upgradeAudioSessionCategory(category, options, clearOptions); | ||
| }); | ||
| return; | ||
| } | ||
| if (category == nil) { | ||
|
||
| category = AVAudioSession.sharedInstance.category; | ||
| } | ||
|
|
@@ -1344,7 +1339,7 @@ static void upgradeAudioSessionCategory(AVAudioSessionCategory category, | |
| [AVAudioSession.sharedInstance setCategory:category withOptions:options error:nil]; | ||
| } | ||
|
|
||
| - (void)setUpCaptureSessionForAudio { | ||
| - (void)setUpCaptureSessionForAudioIfNeeded { | ||
| // Don't setup audio twice or we will lose the audio. | ||
| if (!_mediaSettings.enableAudio || _isAudioSetup) { | ||
| return; | ||
|
|
@@ -1362,11 +1357,13 @@ - (void)setUpCaptureSessionForAudio { | |
| // Setup the audio output. | ||
| _audioOutput = [[AVCaptureAudioDataOutput alloc] init]; | ||
|
|
||
| upgradeAudioSessionCategory(AVAudioSessionCategoryPlayAndRecord, | ||
| AVAudioSessionCategoryOptionDefaultToSpeaker | | ||
| AVAudioSessionCategoryOptionAllowBluetoothA2DP | | ||
| AVAudioSessionCategoryOptionAllowAirPlay, | ||
| 0); | ||
| dispatch_sync(dispatch_get_main_queue(), ^{ | ||
| upgradeAudioSessionCategory(AVAudioSessionCategoryPlayAndRecord, | ||
| AVAudioSessionCategoryOptionDefaultToSpeaker | | ||
| AVAudioSessionCategoryOptionAllowBluetoothA2DP | | ||
| AVAudioSessionCategoryOptionAllowAirPlay, | ||
|
||
| 0); | ||
|
||
| }); | ||
|
|
||
| if ([_audioCaptureSession canAddInput:audioInput]) { | ||
| [_audioCaptureSession addInput:audioInput]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,7 +113,7 @@ NS_ASSUME_NONNULL_BEGIN | |
| - (void)startImageStreamWithMessenger:(NSObject<FlutterBinaryMessenger> *)messenger; | ||
| - (void)stopImageStream; | ||
| - (void)setZoomLevel:(CGFloat)zoom withCompletion:(void (^)(FlutterError *_Nullable))completion; | ||
| - (void)setUpCaptureSessionForAudio; | ||
| - (void)setUpCaptureSessionForAudioIfNeeded; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this called outside the implementation? If not it should be moved to the private category in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is also called from |
||
|
|
||
| @end | ||
|
|
||
|
|
||
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.
Comments should be properly formatted sentences.
https://google.github.io/styleguide/objcguide.html#comments