代码之家  ›  专栏  ›  技术社区  ›  Deepak Sharma

在iOS 13上暂停时强制重画AvPlayerLayer

  •  1
  • Deepak Sharma  · 技术社区  · 5 年前

    我使用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)
        })
    

    作为权宜之计,我用 this 答案在iOS12.4之前有效,但在iOS13测试版6中不再有效。寻找在ios 13上工作的解决方案。

    0 回复  |  直到 5 年前
        1
  •  1
  •   alexkent    5 年前

    在将此作为一个错误报告给苹果并获得一些有用的反馈后,我有一个解决方案:

    player.currentItem?.videoComposition = player.currentItem?.videoComposition?.mutableCopy() as? AVVideoComposition
    

    我得到的解释是:

    avplayer在avplayeritems videocomposition属性获取新实例时重绘帧,或者即使是同一实例,实例的属性也已修改。

    因此,只需复制现有实例,就可以通过创建“新”实例来强制重画。