【问题标题】:Swift. Create an intro video when app launches迅速。在应用启动时创建介绍视频
【发布时间】:2016-06-30 14:07:10
【问题描述】:

我想在我的应用启动时播放本地视频作为介绍视频。用户应该无法取消视频或以任何方式暂停视频,知道我该怎么做吗?

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”

【问题讨论】:

  • 好像没有找到 intro.mp4
  • 是的,我不知道为什么它没有找到它,因为我确实将它添加到构建中,我更新了我的任务;)
  • 您是否将视频添加到您的目标? (点击该视频文件,查看 Xcode 右侧的 File Inspector,查看“Target Membership”框是否选中了您的目标旁边的复选框)

标签: swift video sprite-kit avplayer avplayerviewcontroller


【解决方案1】:

添加您的电影项目。文件检查器 -> 项目名称 -> 目标 -> 项目名称 -> 构建阶段 -> 复制捆绑资源 -> + 按钮

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    • 2015-02-04
    • 1970-01-01
    相关资源
    最近更新 更多