- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self avkitPlayer];
}
- (void)avkitPlayer{
NSString *path = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4"];
self.avPlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:path]];
self.playerlayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
self.playerlayer.frame = self.view.bounds;
if([AVPictureInPictureController isPictureInPictureSupported]){
_avPictureInPictureController = [[AVPictureInPictureController alloc] initWithPlayerLayer:self.playerlayer];
_avPictureInPictureController.delegate = self;
}
[self.avPlayer play];
[self.view.layer addSublayer:self.playerlayer];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInsta
iOS9 iPad 画中画,AVPictureInPictureController使用
最新推荐文章于 2023-08-04 17:30:59 发布
本文介绍如何在iOS9中使用AVPictureInPictureController实现iPad的画中画功能。通过创建AVPlayer和AVPlayerLayer,设置AVPictureInPictureController并监听其状态,实现视频播放时切换到画中画模式。
摘要由CSDN通过智能技术生成