0

我无法在我的 ipad 设备 (ios 6.1) 上播放我使用 AVAdioRecorder 录制的音频文件。但该文件在 ipad 模拟器上播放。

这是我用来记录和保存文件的代码:

NSString *tempPath=[NSString stringWithFormat:@"Documents/%@.aiff",txtName.text];
filePath = [NSHomeDirectory()stringByAppendingPathComponent:tempPath];


NSDictionary *recordSettings =[[NSDictionary alloc] initWithObjectsAndKeys:

 [NSNumber numberWithFloat: 44100.0],AVSampleRateKey,
 [NSNumber numberWithInt: kAudioFormatLinearPCM],AVFormatIDKey,
 [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                                [NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,nil];

soundRecorder =[[AVAudioRecorder alloc] initWithURL: [NSURL fileURLWithPath:filePath] settings: recordSettings error: nil];
soundRecorder.delegate=self;
[soundRecorder record];

以下代码播放录制的文件:

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  

NSString *strPath=[paths objectAtIndex:0];
NSString*strName=[arrayAudio objectAtIndex:clicktag];
strPath=[NSString stringWithFormat:@"%@/%@",strPath,strName];
NSLog(@"path=%@",strPath);
NSError* err;

player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:strPath] error:&err];
player.delegate = self;

  [player prepareToPlay];
[player play];

任何人都可以为这个典型问题提出一些解决方案。我在 stackoverflow 和其他网站上进行了很多搜索,但没有一个解决方案可以帮助我解决我的问题。

提前致谢。

4

1 回答 1

2

我有同样的问题,尝试将会话类别设置为 *PlayAndRecord:

audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: nil];

(翻译自我正在编写的 RubyMotion 代码,如果需要更多工作,请致歉)

于 2013-03-23T02:21:01.317 回答