File tree Expand file tree Collapse file tree
LFCameraPickerControllerDEMO/LFCameraPickerControllerDEMO/class Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments