我想使用iPhone的麥克風記錄:這是我的代碼:操作無法完成。 AVAudioRecorder iPhone SDK
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// the path to write file
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"testing.mp3"];
NSURL *url = [NSURL fileURLWithPath:appFile isDirectory:NO];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatMPEGLayer3], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityLow], AVEncoderAudioQualityKey,
nil];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if ([recorder prepareToRecord] == YES){
[recorder record];
}else {
int errorCode = CFSwapInt32HostToBig ([error code]);
NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode);
}
NSLog(@"BOOL = %d", (int)recorder.recording);
這是錯誤我得到:
Operation could not be completed. (OSStatus error 1718449215.)
我不能,爲什麼這並未制定出不工作,因爲我從一個網站獲得了很多代碼。
喬納森
由於某種原因,它沒有初始化。做'if(記錄器){NSLog:@「是」; }'不會寫入日誌。 –