- (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];
}
视频开始和结束正确但没有声音 为什么?
答案 0 :(得分:1)
@import AVKit;
@import AVFoundation;
@property (nonatomic) AVPlayer *avPlayer;
NSURL *fileURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
self.avPlayer = [AVPlayer playerWithURL:fileURL];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
AVPlayerLayer *videoLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
videoLayer.frame = self.view.bounds;
videoLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view.layer addSublayer:videoLayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:[self.avPlayer currentItem]];
[self.avPlayer play];
尝试使用此代码并对您的代码进行评论并检查您设备中的功能是否正常工作?
答案 1 :(得分:1)
正确的答案是:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];