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];
}
视频开始和完成正确但没有声音 为什么?AVQueuePlayer播放但没有声音
答
正确的答案是这样的:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
答
@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];
试试这个代码和评论你的一个,并检查您的设备做了有益的工作或没有?
+0
声音工作与否? –
+0
我不得不改变一下代码,因为我没有[self.view.layer addSublayer:videoLayer]; –
+0
但声音...不,我不听声音抱歉... –
你测试是在设备或模拟器应用程序? –
没有在设备上... –
有没有设备振动模式?或在声音中,然后增加您的默认声音 –