我有一个Kiosk应用程序,它接收来自Dropbox SDK的视频,将数据保存到临时目录中,并使用AVPlayerLayer在循环中播放。
播放中小型视频(1334x750)时绝对没有问题,但尺寸较大(3888x2592)根本没有出现。有人可以指导我一个可能的解决方案或调试可能出错的方法吗?
这是我的代码:
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()
}