Swift。在应用启动时创建介绍视频
Swift. Create an intro video when app launches
我想在我的应用程序启动时播放本地视频作为介绍视频。用户不应该以任何方式取消或暂停视频,知道我该怎么做吗?
import AVKit
import AVFoundation
class GetInfoView: SKScene {
var moviePlayer = AVPlayerViewController()
var player = AVPlayer()
override func didMoveToView(view: SKView) {
player = AVPlayer(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("intro", ofType: "mp4")!))
moviePlayer.showsPlaybackControls = false
moviePlayer.player = player
self.view?.window?.rootViewController?.presentViewController(moviePlayer, animated: false){
moviePlayer.player?.play()
}
}
}
我已经试过了,但是当它运行时 player = AVPlayer(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("intro", ofType: "mp4")!))
它崩溃了。
错误:
"fatal error: unexpectedly found nil while unwrapping an Optional value"
我不知道问题出在哪里,我确实在我的构建中添加了 "intro.mp4"
添加你的电影project.File Inspector -> Project name -> Targets -> Project Name -> Build Phases -> Copy Bundle Resources -> + button
我想在我的应用程序启动时播放本地视频作为介绍视频。用户不应该以任何方式取消或暂停视频,知道我该怎么做吗?
import AVKit
import AVFoundation
class GetInfoView: SKScene {
var moviePlayer = AVPlayerViewController()
var player = AVPlayer()
override func didMoveToView(view: SKView) {
player = AVPlayer(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("intro", ofType: "mp4")!))
moviePlayer.showsPlaybackControls = false
moviePlayer.player = player
self.view?.window?.rootViewController?.presentViewController(moviePlayer, animated: false){
moviePlayer.player?.play()
}
}
}
我已经试过了,但是当它运行时 player = AVPlayer(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("intro", ofType: "mp4")!))
它崩溃了。
错误:
"fatal error: unexpectedly found nil while unwrapping an Optional value"
我不知道问题出在哪里,我确实在我的构建中添加了 "intro.mp4"
添加你的电影project.File Inspector -> Project name -> Targets -> Project Name -> Build Phases -> Copy Bundle Resources -> + button