我尝试使用IOS9中最近引入的AVPictureInPictureController播放视频,代码如下:
AVPlayer *_AVPlayer = [AVPlayer playerWithURL:url];
AVPlayerLayer *_layer = [AVPlayerLayer playerLayerWithPlayer:_AVPlayer];
_layer.frame = [[UIApplication sharedApplication] delegate].window.bounds;
AVPictureInPictureController *_AVPictureInPictureController = [[AVPictureInPictureController alloc] initWithPlayerLayer:_layer];
_AVPictureInPictureController.delegate = self;
但如何在屏幕中显示_AVPictureInPictureController??我试过了
[self presentViewController:_AVPictureInPictureController animated:YES completion:nil];
和
[self presentMoviePlayerViewControllerAnimated:_AVPictureInPictureController];
但它没有工作):
我也试过
[self.view.layer addSublayer: layer];
但它只在屏幕上显示AVPlayer,没有按钮或控件。
我曾经使用MPMoviePlayerViewController,但由于它在iOS 9中正式弃用,我不能再使用它了。
所以请您帮我显示**_AVPictureInPictureController**!!
先谢谢你了
2条答案
按热度按时间j13ufse21#
当我检查有关AVPictureInPictureController的文档以及Apple在Swift中关于
AVPictureInPictureController
的示例代码时。没有玩家。在Docs中,您需要创建一个Button。而你需要检查当前的视频是sportedAVPictureInPictureController
或不像下面。首先,你需要设置
AVAudioSessionCategoryPlayback
。你需要为你的项目做Xcode功能视图,在后台模式部分选择音频和AirPlay。在应用委托中,您需要设置以下代码:
现在你需要使用以下代码来使用
AVPlayer
播放视频:以下是PIP的按钮切换代码(如果支持):
您现在可以使用它的委托获得check:
**注意:**以上代码仅为示例,可能是您的视频屏幕未满填充设备屏幕。
希望这些信息对你有帮助,可能是你的问题goign得到解决,以便更深入地阅读苹果文档。AVPictureInPictureController
bqucvtff2#
只需使用AVPlayerViewController instread,详情请查看https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/AdoptingMultitaskingOniPad/QuickStartForPictureInPicture.html