//self.Player需要设置为全局的 AVAudioPlayer 播放没有声音的问题
- (void)playAudio
{
NSString * pathUrl =self.model.audioCachesPath.length ? self.model.audioCachesPath : self.model.text_audio;
// 设置外放声音
AVAudioSession * session = [AVAudioSession sharedInstance];
[sessionsetActive:YESerror:nil];
[sessionsetCategory:AVAudioSessionCategoryPlayback error:nil];
// 设置播放
NSError*error=nil;
self.Player=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:pathUrl] error:&error];
[self.Player prepareToPlay];
if(error) {
NSLog(@"创建播放器过程中发生错误,错误信息:%@",error.localizedDescription);
return;
}
[self.Playerplay];
}