1

I am playing a video when an image gets detected on a newspaper, However even if the image is no longer available the video keeps on running.

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

This is what i am doing right now

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
}

Now i am trying to pause it by isHidden on scene but it doesn't work either

  • Possible duplicate of [Check whether the ARReferenceImage is no longer visible in the camera's view](https://stackoverflow.com/questions/49997025/check-whether-the-arreferenceimage-is-no-longer-visible-in-the-cameras-view) – beyowulf Apr 07 '19 at 22:12
  • @beyowulf No in that question person is detecting images and placing nodes on top. In my case my video gets removed from the image when its out of frame but the sound keeps on playing in the back –  Apr 09 '19 at 19:12
  • Did you try the suggestion in the first answer, which is to check the `isTracking` property of the `ARImageAnchor` before pausing in `didUpdateNode`? – beyowulf Apr 09 '19 at 19:22

0 Answers0