我在我的视图中设置了AVPlayer
作为图层,当我提出UIViewController
我通过将比率设置为0来暂停视频时,我会在视图中设置回复率一个。
我还在UIApplicationWillEnterForegroundNotification
和UIApplicationDidEnterBackgroundNotification
发出了相同的通知(在背景上暂停,在前景播放)......
当我呈现VC然后再回来时,我无法让视频继续播放,但是当我去背景并回来时 - 它播放得很好..
不确定我错过了什么..
这就是我设置播放器的方式
self.player = [[AVPlayer alloc]initWithURL:videoUrl];
self.player.allowsExternalPlayback = NO;
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
self.playerLayer.frame = CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height);
self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
self.playerLayer.player.muted = YES;
[self.view.layer insertSublayer:self.playerLayer atIndex:0];