iOS9 画中画 Picture in Picture

画中画 (Picture in Picture)

iOS9系统在iPad上支持 多任务分屏画中画视频播放,画中画视频播放就将视频播放窗口化,然后浮动在屏幕上,此时你可以使用其他APP。但是有限制:1、iOS9 2、iPad,此功能是在iPad上看电影,home返回后无意间发现的好玩的功能。
一、准备工作
1、最好确保iPad的“设置--通用--多任务--持续视频叠层”功能打开。
2、以下为Xcode的工程相关配置
a、设置 Base SDK 为 “Latest iOS”。 
b、打开选项“ target--Capabilities--Background Modes--Audio, AirPlay and Picture in Picture”。
c、确保APP的 audio session使用正确的类型AVAudioSessionCategoryPlayback
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    AVAudioSession *session = [AVAudioSession sharedInstance];
    NSError *error = nil;
    [session setCategory:AVAudioSessionCategoryPlayback error:&error];

    return YES;
}

二、实现方式
 AVKit, AVFoundation, or WebKit 分别提供了一种实现方式。
1、简单方便快捷的实现方式使用AVKit提供的 AVPlayerViewController,定制了UI操作页面,比如进度条、播放暂停按钮等。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    AVAudioSession *session = [AVAudioSession sharedInstance];
    NSError *error = nil;
    [session setCategory:AVAudioSessionCategoryPlayback error:&error];
    

    //AVKit提供的 AVPlayerViewController
    NSURL *movieURL = [[NSBundle mainBundle] URLForResource:@"samplemovie" withExtension:@"mov"];
    AVURLAsset *asset =[AVURLAsset assetWithURL:movieURL];
    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
    AVPlayer* player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
    
    AVPlayerViewController *playerCtr = [[AVPlayerViewController alloc] init];
    playerCtr.player = player;
    [playerCtr.player play];
    self.window.rootViewController = playerCtr;


    return YES;
}


2、如果你想定制播放页面,那就使用AV Foundation提供的AVPlayerLayer(具体用法请参考官方Demo,里面有AVPlayer和AVPlayerLayer的用法)和AVKit提供的 AVPictureInPictureController组合起来实现效果。具体代码请参考官方Swift版本Objecttive-C版
 3、使用  WebKit 提供的  WKWebView  也可以实现。
更多信息 请阅读原文
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值