Jan*_*Jan 3 avfoundation ios swift
我想在纵向模式下在启动画面中播放一些视频 - 全屏.那可能吗?请引导我通过适当的解决方案.
我正在寻找快速的解决方案
UIView使用a AVPlayer和函数创建一个子类createBackground:
import AVFoundation
class BackgroundVideo: UIView {
var player: AVPlayer?
func createBackground(name: String, type: String) { }
}
Run Code Online (Sandbox Code Playgroud)
然后你createBackground可能是这样的:
func createBackground(name: String, type: String) {
guard let path = Bundle.main.path(forResource: name, ofType: type) else { return }
player = AVPlayer(url: URL(fileURLWithPath: path))
player?.actionAtItemEnd = AVPlayerActionAtItemEnd.none;
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.frame
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
self.layer.insertSublayer(playerLayer, at: 0)
player?.seek(to: kCMTimeZero)
player?.play()
}
Run Code Online (Sandbox Code Playgroud)
然后你可以添加更多的东西,比如观察通知:
AVPlayerItemDidPlayToEndTime 用于实现视频循环.UIApplicationWillEnterForeground 用于控制视频循环,从后台恢复后.最后你可以BackgroundView在任何需要的地方附上这个:虚假的闪屏,主屏幕......等等......
| 归档时间: |
|
| 查看次数: |
2816 次 |
| 最近记录: |