首页 > 解决方案 > 如何在 Swift 中预取从 URL 播放的视频

问题描述

我有一个收藏视图,其中包含我从单元 willDisplay播放的视频,如下所示:

  func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
    if let cell = cell as? UserFeedCollectionViewCell {
     let post = feed[indexPath.row]
     cell.videoplayer.play(post: post) 

       }
    }

加载视频需要一些时间(有时需要 1-2 秒),我想提高应用程序的性能。

在这种情况下预取是个好主意吗?我不知道该放什么

 func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) { 
}

标签: swiftperformancevideocollectionviewprefetch

解决方案


推荐阅读