• 1000
Вот код:
class PlaceHolderVideoView : UIView{
let containerImageView = UIImageView(image: #imageLiteral(resourceName: "VideoContainerView"), contentMode: .scaleAspectFit)
override init(frame: CGRect) {
super.init(frame: frame)
setUpUI()
setUpPlayer()
}
fileprivate func setUpUI(){
translatesAutoresizingMaskIntoConstraints = false
addSubview(containerImageView)
containerImageView.fillSuperview()
}
fileprivate func setUpPlayer(){
let urlPathString = Bundle.main.path(forResource: "dance", ofType: "mp4")
if let videoURL = urlPathString{
let url = URL(fileURLWithPath: videoURL)
let player = AVPlayer(url: url)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.containerImageView.frame
self.layer.addSublayer(playerLayer)
player.play()
}
}