I have a Kiosk app that receives videos from the Dropbox SDK, saves the Data into the Temp Directory and plays it back on a loop using AVPlayerLayer.
I have absolutely no issues when playing videos that are small/medium (1334x750), but larger dimensions (3888x2592) do not appear at all. Can somebody direct me to a possible solution or way of debugging what might be going wrong?
Here is my code:
func playVideo(data: Data) {
playerLayer.removeFromSuperlayer()
let path = URL.init(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let url = path.appendingPathComponent("temp.mov")
do {
try data.write(to: url, options: .atomic)
} catch let error {
print("WRITING: \(error)")
}
player = AVPlayer(url: url)
playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = videoView.bounds
videoView.layer.addSublayer(playerLayer)
player.play()
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.loopVideo), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
NotificationCenter.default.post(name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
}
func loopVideo() {
player.seek(to: kCMTimeZero)
player.play()
}