I'm recording a video in the first UIViewController, writing this video to file and I want to show this video in the second UIViewController but sometimes (quite often) there is just a black frame instead of video.
player.status.rawValue
and player.currentItem?.status.rawValue
are 0 every time.
The file is here every time, I can process it, so videoURL
is ok. I'm getting no errors, just the black screen.
videoURLAsset = videoAsset as! AVURLAsset
let videoURL = videoURLAsset.URL
if playerLayer != nil {
player = nil
playerLayer.removeFromSuperlayer()
}
player = AVPlayer(URL: videoURL)
player.volume = 0.0
playerLayer = AVPlayerLayer(player: player)
playerLayer.backgroundColor = UIColor.blackColor().CGColor
playerLayer.frame = CGRectMake(10, 70, screenWidth - 20, screenHeight / 2 - 90)
self.view.layer.addSublayer(playerLayer)
player.play()
What is my mistake?