我試圖同時錄製和播放視頻。這可能與基礎?目前我能夠做到這一點,只要我不記錄音頻。只要我添加到AVCaptureSession的音頻輸入,並重新啓動我收到「AVCaptureSessionWasInterruptedNotification」,並停止錄製的整個事情。Avfoundation - 同時播放和錄製視頻(以及音頻和預覽)
這就是我如何播放視頻。
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
[moviePlayer.view setFrame:self.playerView.bounds];
moviePlayer.useApplicationAudioSession=NO;
self.player = moviePlayer;
[moviePlayer release];
[self.playerView addSubview:player.view];
[player play];
而且我這是怎麼錄製視頻:凡爲我用 「AVCamCaptureManager」 從蘋果AVCam示例代碼
NSError *error;
AVCamCaptureManager *captureManager = [[AVCamCaptureManager alloc] init];
if ([captureManager setupSessionWithPreset:AVCaptureSessionPresetLow error:&error])
{
[self setCaptureManager:captureManager];
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[captureManager session]];
self.captureVideoPreviewLayer= previewLayer;
UIView *view = [self cameraView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = [view bounds];
[captureVideoPreviewLayer setFrame:bounds];
if ([captureVideoPreviewLayer isOrientationSupported])
[captureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
[captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[[captureManager session] startRunning];
[self setCaptureVideoPreviewLayer:captureVideoPreviewLayer];
if ([[captureManager session] isRunning])
{
[captureManager setOrientation:AVCaptureVideoOrientationPortrait];
[captureManager setDelegate:self];
[viewLayer insertSublayer:captureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
NSString *countString = [[NSString alloc] initWithFormat:@"%d", [[AVCaptureDevice devices] count]];
NSLog(@"Device count: %@",countString);
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Failed to start session."
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Input Device Init Failed"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
[captureManager release];
if (![[self captureManager] isRecording]) {
[[self captureManager] startRecording];
}
。
這很有趣,因爲它與此處接受的答案相矛盾:http://stackoverflow.com/a/10559420/954643它說在捕獲會話後啓動音頻會話。 – qix
實際上,文檔對'useApplicationAudioSession'這樣說:「一個布爾值,指示電影播放器是否應該使用該應用的音頻會話(iOS 6.0中不推薦使用該屬性,並且不鼓勵使用該屬性)。」默認值已經是'YES'。 – qix