1

I have a UITableView that I am using to render out tweets that contain gifs. These are returned from Twitter as MP4's so I am using AVPlayer. Using HanekeSwift I am caching the item and then playing it in the tableview. The issue I am having is that any Tweets on screen when the tableview load, do not auto play, I must scroll them off screen and back on before they play.

I configure my AVPlayer in the following function

private func configureAVPlayer(url: URL) {
    cache.fetch(URL: url).onSuccess { [weak self] stream in
        guard let path = URL(string: DiskCache.basePath())?.appendingPathComponent("shared-data/original") else { return }

        let cached = DiskCache(path: path.absoluteString).path(forKey: url.absoluteString)
        let file = URL(fileURLWithPath: cached)

        if !FileManager.default.fileExists(atPath: cached) {
            try! stream.write(to: file, options: .atomicWrite)
        }

        self?.player = AVPlayer(url: file)
        self?.player?.automaticallyWaitsToMinimizeStalling = false
        self?.playerLayer = self?.avPlayerView.layer as? AVPlayerLayer
        guard let player = self?.player else { return }
        self?.playerLayer?.player = player
        self?.player?.play()
    }
}

Following something very similar as described here

However for me, the cell is essentially paused until I scroll.

Tim J
  • 901
  • 4
  • 17
  • Are you doing something different in your `cellForRowAt:` from what you are doing here? Maybe you're making a mistake here that isn't immediately obvious. – rpecka Apr 17 '19 at 19:31
  • `cellForRowAt:` is simply passing in the model, nothing really clever at all – Tim J Apr 17 '19 at 20:24
  • If that's the case, what is causing the player to play once it comes on screen if it is not `cellForRowAt:`? – rpecka Apr 17 '19 at 20:43

0 Answers0