【发布时间】:2014-03-23 22:06:26
【问题描述】:
我使用录音机在文档目录中录制并创建文件,然后使用音频播放器播放。我可以在模拟器和设备上录制它,但我不能只在设备上播放。
请注意 1.我不从文件播放声音,我从NSData播放(我将音乐存储到数据库中,然后检索它们播放) 2.它在模拟器上运行良好,但在设备上失败。
这是我播放音频的代码
- (void)playAudioWithData:(NSData *)data {
[self stopPlayingAudio];
[self stopRecordingAudio];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
self.audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:nil];
[self.audioPlayer play];
}
这是录制的设置:
NSDictionary *audioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:44100],AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatLinearPCM],AVFormatIDKey,
[NSNumber numberWithInt: 1],AVNumberOfChannelsKey,
[NSNumber numberWithInt:AVAudioQualityMedium],AVEncoderAudioQualityKey,nil];
【问题讨论】:
-
你检查数据是否加载了吗?只是在播放前记录数据?
标签: ios cocoa-touch audio avfoundation core-audio