//self.Player需要設(shè)置為全局的?AVAudioPlayer 播放沒(méi)有聲音的問(wèn)題
- (void)playAudio
{
? ? NSString * pathUrl =self.model.audioCachesPath.length ? self.model.audioCachesPath : self.model.text_audio;
? ? // 設(shè)置外放聲音
? ? ? AVAudioSession * session = [AVAudioSession sharedInstance];
? ? ? [sessionsetActive:YESerror:nil];
? ? ? [sessionsetCategory:AVAudioSessionCategoryPlayback error:nil];
? ? ? // 設(shè)置播放
? ? ? NSError*error=nil;
? ? ? self.Player=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:pathUrl]? error:&error];
? ? ? [self.Player prepareToPlay];
? ? ? if(error) {
? ? ? ? ? NSLog(@"創(chuàng)建播放器過(guò)程中發(fā)生錯(cuò)誤,錯(cuò)誤信息:%@",error.localizedDescription);
? ? ? ? ? return;
? ? ? }
? ? ? [self.Playerplay];
}