1

我正在使用 SKVideoNode 使用以下代码显示动画飞溅场景:

    SKVideoNode *video = [SKVideoNode videoNodeWithVideoFileNamed:@"splash_video.mp4"];



    video.position = CGPointMake(CGRectGetMidX(self.frame),
                                 CGRectGetMidY(self.frame));

    [self addChild:video];
    [video play];

我希望在视频播放完成后显示下一个场景。我怎样才能做到这一点?

4

1 回答 1

0

将此添加到您的 viewDidLoad 或其他合适的地方

let videoURL = NSURL(string: url)
let player = AVPlayer(URL: videoURL!)
player.actionAtItemEnd = .None
let videoSpriteKitNode = SKVideoNode(AVPlayer: player)

NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerItemDidReachEnd:", name: AVPlayerItemDidPlayToEndTimeNotification, object: player.currentItem)

并添加此功能:

func playerItemDidReachEnd(notification: NSNotification) {

    if let playerItem = notification.object as? AVPlayerItem {
        //Start your next video here
    }
}
于 2016-01-21T15:44:53.917 回答