一 简述
一种控制器,用于在浮动的可调整大小的窗口中响应用户启动的画中画视频播放。
API_AVAILABLE(ios(9.0), macos(10.15), tvos(14.0)) API_UNAVAILABLE(watchos)
@interface AVPictureInPictureController : NSObject
注意
画中画(PiP)是Apple希望始终在用户控制下的一项用户功能。仅在响应用户的明确请求时才调用PiP。如果某个应用以非用户直接指导的方式调用PiP,则App Store审核小组将拒绝它。
要在iOS中使用画中画,要在Xcode中执行以下步骤:
- 打开后台模式开启 Audio, AirPlay, and Picture in Picture
- 为音频会话配置合适的类别,如
AVAudioSessionCategoryPlayback
、AVAudioSessionCategoryPlayAndRecord
等
重要
不支持子类化和重写其方法,这会导致未定义的行为。
二 官方属性方法
// 当前设备是否支持画中画
+ (BOOL)isPictureInPictureSupported;
// 创建画中画控制器
- (nullable instancetype)initWithPlayerLayer:(AVPlayerLayer *)playerLayer NS_DESIGNATED_INITIALIZER;
// 要播放媒体的播放器层
@property (nonatomic, readonly) AVPlayerLayer *playerLayer;
// 是否允许用户跳过媒体内容
@property (nonatomic) BOOL requiresLinearPlayback API_AVAILABLE(ios(14.0), macos(11.0), tvos(14.0)) API_UNAVAILABLE(watchos);
// 委托对象
@property (nonatomic, weak,<