当检测到的图像在AR中看不见时,如何停止videoNode?

时间:2019-04-07 20:45:11

标签: ios swift xcode scenekit arkit

当在报纸上检测到图像时,我正在播放视频,但是,即使该图像不再可用,该视频仍会继续播放。

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
    videoNode.pause()
} // i tried this function but it stops as soon as it moves

这就是我现在正在做的

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
    let node = SCNNode()

    if let imageAnchor = anchor as? ARImageAnchor {

        let videoNode = SKVideoNode(fileNamed: "HarryPotterVideo.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(videoScene.view?.scene?.isHidden == true) {
            print("Out of view")
        }


    }

    return node
}

现在,我正尝试在isHidden上通过scene暂停它,但是它也不起作用

0 个答案:

没有答案