Ios AVPlayer播放音频,但视频冻结
我有两个Ios AVPlayer播放音频,但视频冻结,ios,objective-c,video,avplayer,Ios,Objective C,Video,Avplayer,我有两个uiviewcontroller,每个控制器都有一个AVPlayer,当它们被推入UINavigationController时,应该播放一个视频文件: -(void)viewWillAppear:(BOOL)animated{ videoView = [[UIView alloc]initWithFrame:self.view.frame]; NSString *filepath = [[NSBundle mainBundle] pathForResource:@"
uiviewcontroller
,每个控制器都有一个AVPlayer
,当它们被推入UINavigationController
时,应该播放一个视频文件:
-(void)viewWillAppear:(BOOL)animated{
videoView = [[UIView alloc]initWithFrame:self.view.frame];
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
self.avPlayer = [AVPlayer playerWithURL:fileURL];
AVPlayerLayer *foregroundLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
foregroundLayer.frame = self.view.frame;
foregroundLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[videoView.layer addSublayer:foregroundLayer];
[self.view addSubview:videoView];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[self.avPlayer currentItem]];
}
-(void)viewDidAppear:(BOOL)animated{
[self.avPlayer play];
}
-(void)playerItemDidReachEnd:(NSNotification *)notification {
[self.navigationController popViewControllerAnimated:NO]
}
第一次按下任何UIViewController
时,播放效果良好。但在那之后,如果我再次按下其中任何一个按钮,声音就会播放,但视频会冻结
我尝试过使用
mpmovieplayervewcontroller
,但行为是一样的。有什么想法吗?奇怪!我也对你这样做。它工作得很好。声音和视频都可以播放。我从这篇文章中读到: