我正在尝试实现一个功能,您可以在AVCaptureSession期间启用或禁用麦克风.这是我启用设备的方式(初始化)
-(void)initMicrophoneInput:(AVCaptureSession*)session{
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
_microphoneInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];
if ([session canAddInput:_microphoneInput]){
[session addInput:_microphoneInput];
} else {
NSLog(@"can't add input");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我禁用/启用麦克风的功能:
- (IBAction)manageMicrophone:(id)sender {
[_captureSession beginConfiguration];
if(_microphoneMuted == NO){
[_captureSession removeInput:_microphoneInput];
}else{
[self initMicrophoneInput:_captureSession];
}
[_captureSession commitConfiguration];
_microphoneMuted = !_microphoneMuted;
}
Run Code Online (Sandbox Code Playgroud)
初始化和移除麦克风效果很好,但是我无法再次启用麦克风.我的_captureSession.inputs包含"微型"设备,但我不再从中获取音频样本- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection;
我正在制作一个框架,当我的苹果手表进入背景和前景时需要做一些事情。
我正在为 Apple Watch 寻找与此 iOS 代码相当的代码,因为 UIApplication 不再存在于 UIKit 中:
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.addObserver(self, selector: "applicationDidEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
Run Code Online (Sandbox Code Playgroud)
你能帮忙的话,我会很高兴