iOS在模拟器上播放音频成功,但在设备上失败
问题描述:
我使用录音机在文档目录中录制和创建文件,然后使用音频播放器播放它。我可以在模拟器和设备上录制它,但我无法在设备上播放它。iOS在模拟器上播放音频成功,但在设备上失败
注意 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];
您是否检查数据是否加载?只是在玩之前记录数据?播放录制的音频的 – Mani