gpt4 book ai didi

ios - 向上滑动(将应用程序置于后台)并且视频正在自定义 AVPLayer 中播放时,如何停止画中画?

转载 作者:行者123 更新时间:2023-12-05 06:04:02 24 4
gpt4 key购买 nike

我正在开发支持画中画的视频播放器。我在该播放器上播放广告和视频内容。当播放器播放广告时,我想限制从设备向上滑动(将应用程序置于后台)时自动画中画。广告完成后,我想让它在应用程序进入后台时以画中画的形式出现。我在自定义播放器中使用 AVPlayer 并在画中画支持中使用 AVPictureInPictureController

我找到了一个与 AVPlayerViewController 相关的解决方案,其中 .allowsPictureInPicturePlayback 属性允许禁用画中画。但是我没有找到 AVPlayerAVPlayerLayer 的任何属性来限制画中画。

请分享处理此案例的可能解决方案。提前致谢。

最佳答案

AVPictureInPictureController 负责在您的应用程序置于后台时自动显示 PIP,而带有 AVPlayerLayer 的 AVPlayer 没有任何设置来管理它。这样你就可以在画中画 Controller 中创建画中画,只有在允许显示画中画时才能创建画中画,否则销毁。

例如,您可以在 View Controller 中创建一个属性来打开和关闭图片 Controller 中的图片:

var pipController: AVPictureInPictureController?

var allowsPictureInPicturePlayback: Bool = false {
didSet {
guard AVPictureInPictureController.isPictureInPictureSupported() else { return }

if allowsPictureInPicturePlayback {
pipController = AVPictureInPictureController(playerLayer: playerLayer)
pipController?.delegate = self
}
else {
pipController = nil
}
}
}

关于ios - 向上滑动(将应用程序置于后台)并且视频正在自定义 AVPLayer 中播放时,如何停止画中画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66476627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com