1.
/// 是否显示过广告 private lazy var isLoadAV = false /// 15秒宣传视频 private var play: AVPlayer? /// 宣传视频背景 private lazy var logoView : UIView = { let v = JYUIModel.createView() v.backgroundColor = UIColor.orange return v }()
2.
/// 添加宣传视频 private func addPromotionalVideo(){ if let filePath = Bundle.main.path(forResource: "测试视频", ofType: "mp4") { let videoUrl = URL(fileURLWithPath: filePath) let playerItem = AVPlayerItem(url: videoUrl) play = AVPlayer(playerItem: playerItem) let player = AVPlayerLayer(player: play) if #available(iOS 11.0, *) { player.frame = CGRect(x: 0, y: 0, width: JYScreenWidth, height: JYScreenHeight - 183 - view.safeAreaInsets.bottom) } else { player.frame = CGRect(x: 0, y: 0, width: JYScreenWidth, height: JYScreenHeight - 183) } logoView.layer.addSublayer(player) play?.play() isLoadAV = true } }
3.
override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() if isLoadAV == false{ addPromotionalVideo() } }