- 播放音频.
- (void)startPlayRecorder:(NSString *)recorderPath
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil; // 加上这两句,否则声音会很小
[audioSession setCategory :AVAudioSessionCategorySoloAmbient error:&err];
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:recorderPath] error:nil];
self.player.numberOfLoops = 0;
[self.player prepareToPlay];
self.player.delegate = self;
[self.player play];
}
- 播放音频结束
#pragma mark - AVAudioPlayerDelegate
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player
successfully:(BOOL)flag
{
[self.player stop];
self.player = nil;
//app录音播放结束后, 恢复网易云,优酷等第三方音乐播放器的后台音乐.
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
if (self.playDelegate && [self.playDelegate respondsToSelector:@selector(voiceDidPlayFinished)]) {
[self.playDelegate voiceDidPlayFinished];
}
}
网友评论