我正在寻找一些帮助来解决看似简单的问题,但我似乎无法弄明白。
我正在使用Cocoapods的Haneke从URL(在我的服务器上)缓存MP4文件,然后使用AVPlayer播放缓存版本。我正在UICOllectionViewCell中设置AVPreviewLayer并运行此代码。问题是玩家最初不会播放视频,但将来会再次播放(在我在uicollectionview中滚动回到该单元格后)
let getUrl = NSURL(string: location)
cache.fetch(URL: getUrl!).onSuccess { (data) in
// Hacky way of getting cache URL from Haneke
let basePath = DiskCache.basePath().stringByAppendingPathComponent("shared-data/original/")
let path = DiskCache(path: basePath, capacity: UINT64_MAX).pathForKey(getUrl!.absoluteString)
let fileURL = NSURL(fileURLWithPath: path)
self.player = AVPlayer(URL: fileURL)
let playerLayer = AVPlayerLayer(player: self.player)
playerLayer.frame = self.view.bounds
cell.videoView.layer.addSublayer(playerLayer)
print("Playing video")
self.player.play()
}