启动屏幕视频完成后如何让我的应用程序自动打开?
How to have my App open automatically after Launch Screen Video finished?
我想整合一个视频作为我的启动屏幕。
我在网上找到了一个教程,但现在我的问题是:我如何将它集成到我的应用程序中,以一种视频将显示一次然后在完成时自动打开应用程序的方式?
目前,视频播放一次(没问题),但随后就停止了 -
如何让它在视频播放完毕后自动打开应用??
这是我的代码:
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController {
var player: AVPlayer?
override func viewDidLoad() {
super.viewDidLoad()
// Load the video from the app bundle.
let videoURL: URL = Bundle.main.url(forResource: "video", withExtension: "mov")!
player = AVPlayer(url: videoURL)
player?.actionAtItemEnd = .none
player?.isMuted = true
let playerLayer = AVPlayerLayer(player: player)
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
playerLayer.zPosition = -1
playerLayer.frame = view.frame
view.layer.addSublayer(playerLayer)
player?.play()
}
func loopVideo() {
player?.seek(to: kCMTimeZero)
player?.play()
}
}
试试这个
Swift3.0
let videoPlayer = AVPlayer(URL: url)
NotificationCenter.default.addObserver(self, selector: Selector(("playerDidFinishPlaying:")),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
func playerDidFinishPlaying(note: NSNotification){
print("Video Finished")
}
可以NSNotification
知道qhwn播放完毕
注册 itemDidFinished 通知:
NotificationCenter.default.addObserver(self, selector: Selector(("playerDidFinishPlaying:")),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
并按如下方式处理 playerDidFinishPlaying 通知:
func playerDidFinishPlaying(notification: NSNotification){
//push your first view controller
}
我想整合一个视频作为我的启动屏幕。 我在网上找到了一个教程,但现在我的问题是:我如何将它集成到我的应用程序中,以一种视频将显示一次然后在完成时自动打开应用程序的方式?
目前,视频播放一次(没问题),但随后就停止了 -
如何让它在视频播放完毕后自动打开应用??
这是我的代码:
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController {
var player: AVPlayer?
override func viewDidLoad() {
super.viewDidLoad()
// Load the video from the app bundle.
let videoURL: URL = Bundle.main.url(forResource: "video", withExtension: "mov")!
player = AVPlayer(url: videoURL)
player?.actionAtItemEnd = .none
player?.isMuted = true
let playerLayer = AVPlayerLayer(player: player)
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
playerLayer.zPosition = -1
playerLayer.frame = view.frame
view.layer.addSublayer(playerLayer)
player?.play()
}
func loopVideo() {
player?.seek(to: kCMTimeZero)
player?.play()
}
}
试试这个 Swift3.0
let videoPlayer = AVPlayer(URL: url)
NotificationCenter.default.addObserver(self, selector: Selector(("playerDidFinishPlaying:")),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
func playerDidFinishPlaying(note: NSNotification){
print("Video Finished")
}
可以NSNotification
知道qhwn播放完毕
注册 itemDidFinished 通知:
NotificationCenter.default.addObserver(self, selector: Selector(("playerDidFinishPlaying:")),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
并按如下方式处理 playerDidFinishPlaying 通知:
func playerDidFinishPlaying(notification: NSNotification){
//push your first view controller
}