用MPMoviePlayerController和Swift播放电影

时间:2014-10-30 10:08:42

标签: ios iphone swift mpmovieplayercontroller

我尝试将MPMoviePlayerController作为视图的子视图,但我试图用Swift做这个,这是我到目前为止所做的:

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    let moviePath = NSBundle.mainBundle().pathForResource("splash", ofType: "mp4")
    let movieURL = NSURL.fileURLWithPath(moviePath!)

    let moviePlayer = MPMoviePlayerController(contentURL: movieURL)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "moviePlayerDidFinishPlaying:" , name: MPMoviePlayerPlaybackDidFinishNotification, object: moviePlayer)

    moviePlayer.controlStyle = .None
    moviePlayer.scalingMode = .Fill
    self.view.addSubview(moviePlayer.view)
    moviePlayer.setFullscreen(true, animated: true)
    moviePlayer.play()
}

func moviePlayerDidFinishPlaying(notification: NSNotification) {

}

它没有用,我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

您可能会忘记添加资源作为"捆绑资源" 按照以下步骤添加:

  1. 在Project Navigator中选择您的项目根目录
  2. 选择"构建阶段"标签
  3. In" Bundle Resources"单击" +"添加资源
  4. 之后我认为你可以让你的代码正常工作。