我有一个应用程序,我正在尝试捕获录音和录像。我可以做一个或另一个但不是两个,问题似乎是我的AVAudioSession。为了录制和播放音频,我使用以下代码:
NSError *error = nil;
audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
[audioSession setActive:YES error:&error];
为了捕获视频我正在使用UIImagePickerController:
- (BOOL)startCameraControllerFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) delegate
{
NSLog(@"AAVC startCameraControllerFromViewController");
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) || (delegate == nil) || (controller == nil))
{
return NO;
}
cameraUI = [[UIImagePickerController alloc] init];
[cameraUI setSourceType:UIImagePickerControllerSourceTypeCamera];
[cameraUI setAllowsEditing:NO];
[cameraUI setDelegate:delegate];
NSLog(@"cameraUI retainCount = %i", [cameraUI retainCount]);
AccessAndrewAppDelegate *AppDelegate = [[UIApplication sharedApplication] delegate];
if (AppDelegate.isMovie)
{
[cameraUI setMediaTypes:[[NSArray alloc] initWithObjects:(NSString *) kUTTypeMovie, nil]];
[cameraUI setVideoQuality:UIImagePickerControllerQualityTypeLow];
AppDelegate.isMovie = NO;
}
else
{
[cameraUI setMediaTypes:[[NSArray alloc] initWithObjects:(NSString *) kUTTypeImage, nil]];
}
[controller presentModalViewController:cameraUI animated:YES];
return YES;
}
当使用AVAudioSession代码并尝试录制视频时,快门将打开然后关闭并冻结,会发生什么。如果我注释掉AVAudioSession配置的视频记录;但是,语音记录无法正常播放。有什么想法吗?
答案 0 :(得分:0)
这已经解决了。我的AVAudioSession在app委托中出现问题。如果启动相机以录制电影,则需要添加一些if逻辑来重新配置音频会话