我的应用程序设置为使用AVCaptureSession从相机录制视频,但是没有音频.我需要做什么来录制音频,然后将其添加到该文件的videoOutput?这是我录制视频的代码:
- AVCaptureSession *session = [[AVCaptureSession alloc] init];
- [session beginConfiguration];
- session.sessionPreset = AVCaptureSessionPresetMedium;
- CALayer *viewLayer = self.vImagePreview.layer;
- NSLog(@"viewLayer = %@",viewLayer);
- AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
- captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
- captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
- [self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];
- AVCaptureDevice *device = [self frontFacingCameraIfAvailable];
- NSError *error = nil;
- AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
- if (!input) {
- // Handle the error appropriately.
- NSLog(@"ERROR: trying to open camera: %@",error);
- }
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
- NSString *documentsDirectoryPath = [paths objectAtIndex:0];
- AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
- NSString *archives = [documentsDirectoryPath stringByAppendingPathComponent:@"archives"];
- NSString *outputpathofmovie = [[archives stringByAppendingPathComponent:@"Test"] stringByAppendingString:@".mp4"];
- NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputpathofmovie];
- [session addInput:input];
- [session addOutput:movieFileOutput];
- [session commitConfiguration];
- [session startRunning];
- [movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
我为音频添加了另一个输入,但它不能与后台的mpmovieplayercontroller一起使用.有什么想法可以播放一个视频,同时记录相机的音频和视频?