I my UIViewController
I have an outlet to UIView
, where I would like to display video using external links. In this case I try to create AVPlayerLayer
and add it to my UIView
outlet.
My code looks like that:
class VievController: UICollectionViewController {
@IBOutlet weak var playerView: UIView!
override func viewDidLoad(){
let playerItem = AVPlayerItem(URL: NSURL(string: ("https://www.youtube.com/watch?v=_yE_XgoWBso"))!)
let avPlayer = AVPlayer(playerItem: playerItem)
let playerLayer = AVPlayerLayer(player: avPlayer)
playerLayer.frame = playerView.bounds
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
playerView.layer.addSublayer(playerLayer)
avPlayer.play()
}
}//end class
I don't know why I don't see video on my UIVIew
outlet - nothing happened. Do you have any suggestion what should I fix?