【发布时间】:2011-01-27 20:25:33
【问题描述】:
我正在尝试使用 iphone 麦克风进行录音:这是我的代码:
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 (recorder) { NSLog:@"Yes"; }所做的那样,不会在日志中写入“是”。
标签: iphone objective-c iphone-sdk-3.0 ios-simulator