2013-11-21 43 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 我計算過,很多我自己,但還是覺得不舒服有這些異常。使用不同的音頻格式,同時錄製使例外消失。然而,我想使用無損格式,這確實會導致這些異常。希望這可以幫助。