本文介绍了AVQueuePlayer播放但没有声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (void)playVideoInteractionNarration:(NSString *)vNarr{

[self pauseActionExecution];

NSURL *u = [NSURL fileURLWithPath:vNarr];
AVQueuePlayer *player = [[AVQueuePlayer alloc] initWithURL:u];
self.controller = [[AVPlayerViewController alloc]init];
controller.player = player;
controller.showsPlaybackControls=NO;

[controller.player setActionAtItemEnd:AVPlayerActionAtItemEndAdvance];

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(videoNarrationFinishedPlaying:)
 name:AVPlayerItemDidPlayToEndTimeNotification
 object:player.currentItem];
//NSLog(@"MPVIDEOOOOOOO %@", player);

[controller.player setVolume:1.0];
[controller.player setMuted:NO];
[controller setViewInCurrentController];
[controller.player play];

}

- (void)videoNarrationFinishedPlaying:(NSNotification *) aNotification{

AVPlayerItem * item = [aNotification object];

[self.controller removeViewInCurrentController];
[[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:AVPlayerItemDidPlayToEndTimeNotification
                                              object:item];

[self.controller.player pause];
[self.controller release];
[self playActionExecution];
}

视频开始和结束正确但没有声音
为什么?

the video start and finish correctly but NO soundwhy ?

推荐答案

正确的答案是:

  [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

这篇关于AVQueuePlayer播放但没有声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-23 16:05