0
나는 avcapture 세션에서 비디오를 녹화하려고하는데 동시에 타격을 감지하지만 녹화 버튼을 클릭하면 카메라가 정지되는 문제에 직면합니다. 한 가지 중요한 일은 avcapture 세션에서 오디오 입력을 제거한 다음 잘 작동하는 모든 것을 처리해야합니다. 어떤 도움 감지되어야 .. 버튼 기록AVCapture 세션 및 마이크에서 타격을 감지
코드
[recordButton setEnabled:NO];
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.03 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
} else{
NSLog(@"error%@",[error description]);
}
[recordButton setImage:[UIImage imageNamed:@"record-h.png"] forState:UIControlStateNormal];
[timerLbl setHidden:false];
[lblHr setHidden:false];
[lblMnt setHidden:false];
[self toggleRecording:nil];
startDate = [NSDate date] ;
startDate = [[startDate dateByAddingTimeInterval:((-1)*(pauseTimeInterval))] retain];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];
}
다음과 같이 내가 avcapture 세션을 설정하고이고 녹화 개시하기위한 코드 다음과 같다 [자기 toggleRecording을 : 닐] ;
- (IBAction)toggleRecording:(id)sender
{
// Start recording if there isn't a recording running. Stop recording if there is.
if ([UIImagePickerController isSourceTypeAvailable:SOURCETYPE]) {
if (![[[self captureManager] recorder] isRecording])
[[self captureManager] startRecording];
else
[[self captureManager] stopRecording];
}
}
을 다음과
- (BOOL) setupSession { BOOL success = NO; // Set torch and flash mode to auto if ([[self backFacingCamera] hasFlash]) { if ([[self backFacingCamera] lockForConfiguration:nil]) { if ([[self backFacingCamera] isFlashModeSupported:AVCaptureFlashModeAuto]) { [[self backFacingCamera] setFlashMode:AVCaptureFlashModeAuto]; } [[self backFacingCamera] unlockForConfiguration]; } } if ([[self backFacingCamera] hasTorch]) { if ([[self backFacingCamera] lockForConfiguration:nil]) { if ([[self backFacingCamera] isTorchModeSupported:AVCaptureTorchModeAuto]) { [[self backFacingCamera] setTorchMode:AVCaptureTorchModeAuto]; } [[self backFacingCamera] unlockForConfiguration]; } } // Init the device inputs AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self frontFacingCamera] error:nil]; AVCaptureDeviceInput *newAudioInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self audioDevice] error:nil]; // Setup the still image file output AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init]; NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil]; [newStillImageOutput setOutputSettings:outputSettings]; [outputSettings release]; // Create session (use default AVCaptureSessionPresetHigh) AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init]; // Add inputs and output to the capture session if ([newCaptureSession canAddInput:newVideoInput]) { [newCaptureSession addInput:newVideoInput]; } if ([newCaptureSession canAddInput:newAudioInput]) { [newCaptureSession addInput:newAudioInput]; } if ([newCaptureSession canAddOutput:newStillImageOutput]) { [newCaptureSession addOutput:newStillImageOutput]; } [self setStillImageOutput:newStillImageOutput]; [self setVideoInput:newVideoInput]; [self setAudioInput:newAudioInput]; [self setSession:newCaptureSession]; [newStillImageOutput release]; [newVideoInput release]; [newAudioInput release]; [newCaptureSession release]; // Set up the movie file output NSURL *outputFileURL = [self tempFileURL]; AVCamRecorder *newRecorder = [[AVCamRecorder alloc] initWithSession:[self session] outputFileURL:outputFileURL]; [newRecorder setDelegate:self]; // Send an error to the delegate if video recording is unavailable if (![newRecorder recordsVideo] && [newRecorder recordsAudio]) { NSString *localizedDescription = NSLocalizedString(@"Video recording unavailable", @"Video recording unavailable description"); NSString *localizedFailureReason = NSLocalizedString(@"Movies recorded on this device will only contain audio. They will be accessible through iTunes file sharing.", @"Video recording unavailable failure reason"); NSDictionary *errorDict = [NSDictionary dictionaryWithObjectsAndKeys: localizedDescription, NSLocalizedDescriptionKey, localizedFailureReason, NSLocalizedFailureReasonErrorKey, nil]; NSError *noVideoError = [NSError errorWithDomain:@"AVCam" code:0 userInfo:errorDict]; if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) { [[self delegate] captureManager:self didFailWithError:noVideoError]; } } [self setRecorder:newRecorder]; [newRecorder release]; success = YES; return success; }