Skip to content

Commit 1797b01

Browse files
committed
-修复无法恢复原音频的问题
1 parent 4312b52 commit 1797b01

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

LFCameraPickerControllerDEMO/LFCameraPickerControllerDEMO/class/LFCameraPickerController.m

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ - (void)viewDidLoad {
6565
// Do any additional setup after loading the view.
6666
[self setNavigationBarHidden:YES];
6767

68+
NSError *error;
69+
[[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];
70+
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDuckOthers error:&error];
71+
[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeVideoRecording error:&error];
72+
73+
if (error) {
74+
NSLog(@"AVAudioSession error:%@", error);
75+
}
76+
6877
/** 监听应用回到前台通知 */
6978
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
7079
}
@@ -76,9 +85,19 @@ - (void)viewWillDisappear:(BOOL)animated {
7685

7786
- (void)dealloc
7887
{
79-
[[NSNotificationCenter defaultCenter] removeObserver:self];
80-
/** 恢复原来的音频 */
81-
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
88+
89+
}
90+
91+
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
92+
{
93+
[super dismissViewControllerAnimated:flag completion:^{
94+
[[NSNotificationCenter defaultCenter] removeObserver:self];
95+
/** 恢复原来的音频 */
96+
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
97+
if (completion) {
98+
completion();
99+
}
100+
}];
82101
}
83102

84103
- (void)applicationWillEnterForeground:(NSNotification *)notify

0 commit comments

Comments
 (0)