2013-11-21 39 views
0

我正在运行sample code音频录制(源代码可在本文结尾处下载)。该代码是这样的AVAudioRecorder在prepareToRecord上抛出异常

NSArray *pathComponents = [NSArray arrayWithObjects: 
          [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], 
          @"MyAudioMemo.m4a", 
          nil]; 
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents]; 

// Setup audio session 
AVAudioSession *session = [AVAudioSession sharedInstance]; 
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; 

// Define the recorder setting 
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init]; 

[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey]; 
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]; 

// Initiate and prepare the recorder 
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:nil]; 
recorder.delegate = self; 
recorder.meteringEnabled = YES; 
[recorder prepareToRecord]; 

然而,在prepareToRecord在模拟器上运行时抛出异常:

enter image description here

它不记录,它会运行良好,如果我只是关闭休息指出例外。但这很烦人。怎么了?

+0

音频演示应用程序完美。我不明白为什么它会为你崩溃。 –

+0

这很奇怪。我重新下载,以确保我没有插手任何东西。我想这只是我的系统。 – huggie

+0

@Bhumeshwerkatre顺便说一句,你是否为所有例外添加了断点? – huggie

回答

3

我也收到了这个异常。寻找解决方案。重要的是要注意,如果启用异常断点,您只能看到这些异常。该应用程序正常运行,但这是关系。我会继续调查。

编辑: 好,答案就在这里:AVAudioPlayer throws breakpoint in debug mode 我计算过,很多我自己,但还是觉得不舒服有这些异常。使用不同的音频格式,同时录制使例外消失。然而,我想使用无损格式,这确实会导致这些异常。希望这可以帮助。