//创建播放器
-(AVAudioPlayer *)audioPlayer{
// if (!_audioPlayer) {
NSError *error=nil;
NSData *data = [NSData dataWithContentsOfURL:self.savedRecordPath];
_audioPlayer = [[AVAudioPlayer alloc] initWithData:data fileTypeHint:AVFileTypeWAVE error:&error];
// _audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:self.savedRecordPath error:&error]; 直接使用这种方法会导致录音播放不完整
NSLog(@"创建播放器的时候拿到的录音的路径:%@", self.savedRecordPath);
_audioPlayer.numberOfLoops=0;
[_audioPlayer setVolume:1];
[_audioPlayer prepareToPlay];
_audioPlayer.delegate = self;
if (error) {
NSLog(@"创建播放器过程中发生错误,错误信息:%@",error.localizedDescription);
return nil;
}
// }
return _audioPlayer;
}