我创建了一个AR应用程序,可以在特定的图像锚点上播放视频。我想扩展该应用程序以处理多个图像。现在,当我扫描第一个图像时,它会播放视频,当我扫描第二个图像时,它会播放另一个视频。这里出现的问题是两个视频同时播放。
守则:
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
if let imageAnchor = anchor as? ARImageAnchor {
//below code needs to be duplicated in order to add more news
if imageAnchor.referenceImage.name == "harrypotter" {
let videoNode = SKVideoNode(fileNamed: "harrypotter.mp4")
videoNode.play()
let videoScene = SKScene(size: CGSize(width: 480, height: 360))
videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2)
videoNode.yScale = -1.0
videoScene.addChild(videoNode)
let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)
plane.firstMaterial?.diffuse.contents = videoScene
let planeNode = SCNNode(geometry: plane)
planeNode.eulerAngles.x = -.pi / 2
node.addChildNode(planeNode)
}
if imageAnchor.referenceImage.name == "deatheater" {
let videoNode = SKVideoNode(fileNamed: "deatheater.mp4")
videoNode.play()
let videoScene = SKScene(size: CGSize(width: 480, height: 360))
videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2)
videoNode.yScale = -1.0
videoScene.addChild(videoNode)
let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)
plane.firstMaterial?.diffuse.contents = videoScene
let planeNode = SCNNode(geometry: plane)
planeNode.eulerAngles.x = -.pi / 2
node.addChildNode(planeNode)
}
我尝试使用2个if条件,这有助于在特定图像锚点上播放视频。现在,当我扫描第一个图像时,它会播放视频,当我扫描第二个图像时,它会播放另一个视频。这里出现的问题是两个视频同时播放。我希望每当我播放另一个视频时,第一个视频都应自动停止。
1条答案
按热度按时间des4xlb01#
欢迎您来到比利时!
以下是一些建议,可帮助您获得所需内容并改进代码。
我不熟悉这些API,但您会看到以下内容:
祝你好运。