【发布时间】:2017-07-24 19:26:05
【问题描述】:
构建我的第一个应用程序并尝试将背景视频水平放置。
下面是我正在使用的代码
override func viewDidLoad()
{
super.viewDidLoad()
let URL = Bundle.main.url(forResource: "homedocapp", withExtension: "mp4")
Player = AVPlayer.init(url: URL!)
PlayerLayer = AVPlayerLayer(player: Player)
PlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
PlayerLayer.frame = self.view.frame; PlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
PlayerLayer.zPosition = -1
Player.actionAtItemEnd = AVPlayerActionAtItemEnd.none
self.view.layer.addSublayer(PlayerLayer)
Player.play()
view.layer.insertSublayer(PlayerLayer, at: 0)
NotificationCenter.default.addObserver(self, selector: #selector(playerItemReachEnd(notification:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: Player.currentItem)
}
提前感谢您
【问题讨论】:
标签: ios swift swift3 xcode8 avplayer