ios – Easy methods to guarantee that just one video shall be performed at a time?


I created an AR App that performs a video on a specific picture anchor. I needed to increase that software to take care of greater than 1 picture. Now after I scan 1st picture it performs the video, and after I scan the 2nd picture it performs one other video. The Drawback that happens right here is each movies are taking part in concurrently.

The Code:

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

    let node = SCNNode()
    
    if let imageAnchor = anchor as? ARImageAnchor {
        
        //beneath code must be duplicated as a way to add extra information
        
        if imageAnchor.referenceImage.title == "harrypotter" {
            
            let videoNode = SKVideoNode(fileNamed: "harrypotter.mp4")
            
            videoNode.play()
            
            let videoScene = SKScene(measurement: CGSize(width: 480, top: 360))
            
            videoNode.place = CGPoint(x: videoScene.measurement.width / 2, y: videoScene.measurement.top / 2)
            
            videoNode.yScale = -1.0
            
            videoScene.addChild(videoNode)
            
            
            let airplane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, top: imageAnchor.referenceImage.physicalSize.top)
            
            airplane.firstMaterial?.diffuse.contents = videoScene
            
            let planeNode = SCNNode(geometry: airplane)
            
            planeNode.eulerAngles.x = -.pi / 2
            
            node.addChildNode(planeNode)
            
        }

        if imageAnchor.referenceImage.title == "deatheater" {
         
         let videoNode = SKVideoNode(fileNamed: "deatheater.mp4")
            
            videoNode.play()
         
         let videoScene = SKScene(measurement: CGSize(width: 480, top: 360))
         
         videoNode.place = CGPoint(x: videoScene.measurement.width / 2, y: videoScene.measurement.top / 2)
         
         videoNode.yScale = -1.0
         
         videoScene.addChild(videoNode)
         
         
         let airplane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, top: imageAnchor.referenceImage.physicalSize.top)
         
         airplane.firstMaterial?.diffuse.contents = videoScene
         
         let planeNode = SCNNode(geometry: airplane)
         
         planeNode.eulerAngles.x = -.pi / 2
         
         node.addChildNode(planeNode)
         
     }

i attempted to make use of 2 if situations which helps to play a video on a specific picture anchor. Now after I scan 1st picture it performs the video, and after I scan the 2nd picture it performs one other video. The Drawback that happens right here is each movies are taking part in concurrently. I would like that each time I play the one other video the first video ought to be cease routinely.

Leave a Reply