ios - 在 iOS 13 上暂停时强制重绘 AVPlayerLayer

标签 ios avfoundation avplayer core-image cifilter

我使用 CoreImage 将实时效果应用于使用 AVPlayer 播放的视频。问题是当播放器暂停时,如果您使用 slider 调整过滤器参数,则不会应用过滤器。

  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)
    })

作为解决方法,我使用了 this在 iOS 12.4 之前有效的答案,但在 iOS 13 beta 6 中不再适用。寻找适用于 iOS 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"实例来强制重绘。

关于ios - 在 iOS 13 上暂停时强制重绘 AVPlayerLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57459354/

相关文章:

ios - 如何显示AVPictureInPictureController?

swift - 如何在 TableViewCell 中嵌入 AVPlayerViewController

javascript - 检测 ios11 设备是否处于低功耗模式,以防止在正常正确自动播放视频时出现不良用户体验

ios - 在 iOS 上模拟 VoiceOver 辅助功能点击

ios - UIAlertView 上的按钮

iphone - 在 iPhone 上合并两个 .caf 文件

ios - AVPlayer 停止播放并且不会再次恢复

ios - 在 channelCount 条件下从缓冲区播放时 AKPlayer 崩溃

swift - 添加图层后,播放按钮不会出现在 AVPlayer 中 - iOS 16

ios - 应该在哪里快速声明协议(protocol)?