我正在尝试录制和保存 mp3 文件,所以我使用以下代码
NSString* d = @" ar/mobile/Applications/86F15C5E-66EC-4071-95EB-96CDE64B5948/Library/Application Support/P/5720/5720/Report/Report0.mp3"
NSURL *soundFileURL = [NSURL fileURLWithPath:d];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
[audioRecorder prepareToRecord];
}
开始记录我使用
[audioRecorder record];
对于 mp3 我有错误 错误:操作无法完成。 (操作系统状态错误 1718449215。)
如果我把它保存为wav,什么都不记录,文件是0字节
我是不是遗漏了什么,知道如何解决吗
最佳答案
你没有展示 Dpath 的定义方式......
NSString * filePath = [NSHomeDirectory()stringByAppendingPathComponent: [NSString stringWithFormat:@"Documents/%@.mp3",songTitle]];
// more code
recorder = [[AVAudioRecorder alloc] initWithURL: [NSURL fileURLWithPath:filePath settings: recordSettings error: nil];
关于iphone - 将音频文件录制为 mp3 或 wav,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9312032/