[英]iOS: Audio recording setup fails in simulator, but not on my device?
我正在我的應用程序中錄制音頻。 該應用程序可以在裝有iOS 7的iPhone 5C中正常運行,但在模擬器中無法運行(iPhone Retina 3,5英寸/ 4英寸/ 4英寸/ 64英寸)
這是設置音頻的代碼:
-(void)setupAudio{
_audioMessageLabel.text = @"...Bereit für Aufnahme...";
[_stopButton setEnabled:NO];
[_playButton setEnabled:NO];
// Set the audio file
NSString *guid = [[NSUUID new] UUIDString];
_dateiName = [NSString stringWithFormat:@"audio-notiz-%@.m4a", guid];
NSLog(@"dateiName: %@", _dateiName);
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
_dateiName,
nil];
_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
NSError *error = nil;
recorder = [[AVAudioRecorder alloc] initWithURL:_outputFileURL settings:recordSetting error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];
}
}
它在控制台的最后一行[recorder prepareToRecord]
帶有(lldb)失敗
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.