iphone - 将音频文件录制为 mp3 或 wav

标签 iphone ios ipad avaudiorecorder

我正在尝试录制和保存 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/

相关文章:

iphone - 对 UIImageView 进行旋转后,我应该如何检查触摸点是否在 UIImageView 区域内?

objective-c - CAL层转换

iphone - 通用应用如何区分iPhone和iPad?

objective-c - 将 Twitter 帐户添加到 ABRecordRef(人员)的最简单方法

ios - 仅从存在用户 UID 的节点获取特定的子值

objective-c - 从 TableView 中删除行

iphone - 如何在 Apple 示例 MultipleDetailViews 的详细 View 中推送 View Controller ?

ios - 从 Parse 中删除推送通知历史条目

iphone - addSubview 到 View - 显示为 PageCurlDown

iphone - 如何禁用 UITextField 或键盘的文本自动更正?