gpt4 book ai didi

ios - 检测本地视频何时结束并移动到另一个场景

转载 作者:行者123 更新时间:2023-11-30 11:03:40 25 4
gpt4 key购买 nike

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

这是代码:

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
}
}

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

最佳答案

您可以像这样触发通知:

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



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

关于ios - 检测本地视频何时结束并移动到另一个场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52988332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com