检测本地视频何时结束并移至另一个场景 [英] Detect when the local video ended and move to another Scene

查看:50
本文介绍了检测本地视频何时结束并移至另一个场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测本地视频已结束并移至另一个场景?

How to detect that the local video ended and move to another Scene?

这是代码:

import SpriteKit
import GameplayKit
import AVKit
import AVFoundation

class intro: SKScene {

  override func didMove(to view: SKView) {
      let urlStr = Bundle.main.path(forResource: "Opening", ofType: "mp4")
      let url = NSURL(fileURLWithPath: urlStr!)

      let player = AVPlayer(url: url as URL)

      let videoNode = SKVideoNode(avPlayer: player)
      videoNode.position = CGPoint(x: 0, y: 0)
      videoNode.size = CGSize(width: self.frame.width, height: self.frame.height)
      videoNode.zPosition = 1

      addChild(videoNode)
      videoNode.play()
  }

  override func update(_ currentTime: TimeInterval) {
      // Called before each frame is rendered
  }
}

视频结束后,我需要知道如何移动到另一个场景.谢谢.

i need to know how to move to another scene once the video ends . thanks.

推荐答案

您可以像这样触发通知:

You can fire notification like this:

  NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidFinishPlaying),
                                               name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
                                               object: self.player!.currentItem)



 @objc func playerDidFinishPlaying(){
    print("Player finished")
}

这篇关于检测本地视频何时结束并移至另一个场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆