我想在我的应用启动时播放本地视频作为介绍视频。用户不应该取消视频或以任何方式暂停它,不知道我该怎么做?
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"到我的构建
答案 0 :(得分:3)
添加你的电影项目.File Inspector - >项目名称 - >目标 - >项目名称 - >构建阶段 - >复制捆绑资源 - > +按钮