在 iOS 13 上暂停时强制重绘 AVPlayerLayer
Force Redraw of AVPlayerLayer when it is paused on iOS 13
我使用 CoreImage 将实时效果应用于使用 AVPlayer 播放的视频。问题是播放器暂停时,如果您使用滑块调整滤镜参数,则不会应用滤镜。
let videoComposition = AVMutableVideoComposition(asset: asset, applyingCIFiltersWithHandler: {[weak self] request in
// Clamp to avoid blurring transparent pixels at the image edges
let source = request.sourceImage.clampedToExtent()
let output:CIImage
if let filteredOutput = self?.runFilters(source, filters: array)?.cropped(to: request.sourceImage.extent) {
output = filteredOutput
} else {
output = source
}
// Provide the filter output to the composition
request.finish(with: output, context: nil)
})
作为一种解决方法,我使用了 的答案,该答案一直有效到 iOS 12.4,但在 iOS 13 beta 6 中不再有效。寻找适用于 [=17= 的解决方案] 13.
将此作为错误报告给 Apple 并获得一些有用的反馈后,我有一个修复程序:
player.currentItem?.videoComposition = player.currentItem?.videoComposition?.mutableCopy() as? AVVideoComposition
我得到的解释是:
AVPlayer redraws a frame when AVPlayerItem’s videoComposition property gets a new instance or, even if it is the same instance, a property of the instance has been modified.
因此;只需复制现有实例即可通过创建 'new' 实例来强制重绘。
我使用 CoreImage 将实时效果应用于使用 AVPlayer 播放的视频。问题是播放器暂停时,如果您使用滑块调整滤镜参数,则不会应用滤镜。
let videoComposition = AVMutableVideoComposition(asset: asset, applyingCIFiltersWithHandler: {[weak self] request in
// Clamp to avoid blurring transparent pixels at the image edges
let source = request.sourceImage.clampedToExtent()
let output:CIImage
if let filteredOutput = self?.runFilters(source, filters: array)?.cropped(to: request.sourceImage.extent) {
output = filteredOutput
} else {
output = source
}
// Provide the filter output to the composition
request.finish(with: output, context: nil)
})
作为一种解决方法,我使用了
将此作为错误报告给 Apple 并获得一些有用的反馈后,我有一个修复程序:
player.currentItem?.videoComposition = player.currentItem?.videoComposition?.mutableCopy() as? AVVideoComposition
我得到的解释是:
AVPlayer redraws a frame when AVPlayerItem’s videoComposition property gets a new instance or, even if it is the same instance, a property of the instance has been modified.
因此;只需复制现有实例即可通过创建 'new' 实例来强制重绘。