记录音频文件为MP3或WAV

记录音频文件为MP3或WAV

问题描述:

我试图记录和saave MP3文件,所以我用下面的代码记录音频文件为MP3或WAV

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我得到错误 错误:操作无法完成。 (OSStatus错误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]; 
+0

我更新的代码 – AMH 2012-02-16 14:27:40