ios - 在登录页面全屏播放视频

标签 ios swift

我想在 swift 3.0 的登录屏幕上播放背景视频。但是当我运行程序时,视频无法全屏显示。它正在工作 我该如何解决这个问题?这是 Storyboard图片。

enter image description here

enter code here
import UIKit
import AVFoundation

class ViewController: UIViewController {

var Player: AVPlayer!
var PlayerLayer: AVPlayerLayer! 


var frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.


    let URL:NSURL = NSURL(string: "https://firebasestorage.googleapis.com/v0/b/pattyapp-34c16.appspot.com/o/dog1.mp4?alt=media&token=98ab3c41-c645-4535-a70b-41511b5df602")!


    Player = AVPlayer.init(url: URL as URL)


    PlayerLayer = AVPlayerLayer(player: Player)
    PlayerLayer.videoGravity = AVLayerVideoGravityResizeAspect
    PlayerLayer.frame.size = frame.size


    Player.actionAtItemEnd = AVPlayerActionAtItemEnd.none
    Player.isMuted = true

    Player.play()

    view.layer.insertSublayer(PlayerLayer, at: 0)
    NotificationCenter.default.addObserver(self, selector: #selector(playerItemReachEnd(notification:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: Player.currentItem)
}
func playerItemReachEnd(notification: NSNotification) {

    Player.seek(to: kCMTimeZero)

}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

最佳答案

在后台播放视频您可以使用以下第三方库列表来解决您的问题。

VideoSplashKit

HAPlayerView

关于ios - 在登录页面全屏播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46809844/

相关文章:

ios - EAS 构建 - rsync 错误 : some files could not be transferred (code 23) error

iphone - iOS 对 vpn 上的 wifi 的可达性帮助不大

ios - 由于xcodebuild失败而无法启动WebDriverAgent:xcodebuild失败,代码为70

ios - UICollectionViewCells 在 reloadData() 后不显示

ios - 如何更改动态 UITableView xcode 项目中单元格中的数据?

ios - 仅在代码中添加按钮?

ios processing.js准系统模板

ios - 谷歌登录API

ios - 如何在 iOS Swift 中处理推送通知点击?

swift - UnsafeRawPointer 假设MemoryBound 与 bindMemory