Im trying to display a local recorded video in AVPlayerLayer , which sometimes works. I hear the sound from the recorded video, but I do not see the video. Sometimes both video and audio work, sometimes only audio.
I tried working with AVPlayerLayer and AVPlayerViewController , but in both cases the same problem occurs. So this is not due to incorrect frames.
AVPlayerViewController sample code:
let player = AVPlayer(url: url) let playerController = AVPlayerViewController() playerController.player = player self.present(playerController, animated: true) { player.play() }
AVPlayerLayer sample code:
let asset = AVAsset(url: url) let item = AVPlayerItem(asset: asset) self.player = AVPlayer(playerItem: item) self.player?.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions(), context: nil) self.playerLayer = AVPlayerLayer(player: self.player!) self.playerLayer?.frame = imageView.bounds imageView.layer.addSublayer(self.playerLayer!)
Change 1:
When observing the playerβs state, the error is nil , and the status is readyToPlay
Edit 2:
Works great if the URL is removed.
Edit 3:
It seems to work if I wait a couple of seconds after the export of the video is complete. Can there be something with a file that is not 100% written to the file system?
Edit 4: Video problems, in which case he played a third time.
source share