SKVideoNode不播放视频

时间:2016-03-31 12:53:09

标签: ios swift sprite-kit skvideonode

我一直在研究这个问题已经有一段时间了,尝试在stackoverflow上应用类似问题的解决方案,但到目前为止还没有运气。

我的代码:

override func didMoveToView(view: SKView) {
  if let path = NSBundle.mainBundle().pathForResource("stars", ofType: "mov") {
    let videoUrl = NSURL(fileURLWithPath: path)
    player = AVPlayer(URL: videoUrl)
    videoNode = SKVideoNode(AVPlayer: player)
    videoNode.size = frame.size
    videoNode.position = CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMidY(frame))
    addChild(videoNode)
    videoNode.play()
    NSNotificationCenter.defaultCenter().addObserver(self,
                                            selector: #selector(GameScene.playerItemDidReachEnd(_:)),
                                                name: AVPlayerItemDidPlayToEndTimeNotification,
                                              object: nil)
    setupView(true)
  } else { // Triggered if the video couldn't be found inside the project bundle
    print("Couldn't find the video")
  }
}

func playerItemDidReachEnd(notification: NSNotification) {
  player.seekToTime(kCMTimeZero)
  videoNode.play()
}

这是我在控制台上获得的一行:

  

< SKMetalLayer:0x127eda5a0> :调用-display无效。

0 个答案:

没有答案