Friday, December 2, 2022
HomeIOS Developmentios - ARKit: A number of movies PLUS play/pause performance that resumes...

ios – ARKit: A number of movies PLUS play/pause performance that resumes the right video


Studying and LOVING ARKit, I am going by means of a web-based class the place the venture is to create the Harry Potter-like newspaper that performs a video when the digital camera seems to be at a picture on the paper. I am taking the venture a step additional in making an attempt to do two issues:

  1. Have the video pause when the digital camera strikes off the picture linked to the video and in addition
  2. Play a number of video primarily based off a number of pictures

I received the Play/Pause function to work utilizing this methodology():

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
    guard let imageAnchor = anchor as? ARImageAnchor else {return}

    if imageAnchor.isTracked {
        videoNode.play()
    } else {
        videoNode.pause()
    }
}

And I received a number of movies to play utilizing two international properties:

var movieName = "Pals.mp4"
var videoNode = SKVideoNode(fileNamed: "Pals.mp4")

After which throughout the ARSCNViewDeleegate methodology, I added the next code…

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
    let node = SCNNode()
    
    if let imageAnchor = anchor as? ARImageAnchor {
        
        if imageAnchor.referenceImage.identify == "HarryAndFriends" {
            movieName = "Pals.mp4"
        } else if imageAnchor.referenceImage.identify == "Practice" {
            movieName = "TrainStation.mp4"
        }
        
        videoNode = SKVideoNode(fileNamed: movieName)
        videoNode.play()
        
        let videoScene = SKScene(dimension: CGSize(width: 1280, peak: 720))
        videoNode.place = CGPoint(x: videoScene.dimension.width / 2, y: videoScene.dimension.peak / 2)
        videoNode.yScale = -1.0
        videoScene.addChild(videoNode)
        
        let airplane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, peak: imageAnchor.referenceImage.physicalSize.peak)
        airplane.firstMaterial?.diffuse.contents = videoScene
        
        let planeNode = SCNNode(geometry: airplane)
        planeNode.eulerAngles.x = -.pi / 2
        
        node.addChildNode(planeNode)
    }
    
    return node
}

This principally works!

I can observe Video1, transfer the digital camera off of Image1, and Video1 pauses. After I level the digital camera again on Image1, Video1 resumes. Excellent! Then shifting to Image2, Video2 begins enjoying, because it ought to. I can transfer the digital camera off of Image2, and Video2 pauses, because it ought to.

Nevertheless, once I place the digital camera again on Image1, Video1 seems, as and the place it ought to, however Video2 resumes enjoying (I can hear the audio from Video2). Video1 doesn’t play and continues to be paused the place I left off.

Video2 is by some means saved in reminiscence, and I can not determine methods to get it to swtich again.

I pulled data from these posts:

Monitoring a number of pictures and play their movies in ARkit2

A number of picture monitoring ARKit

ARKit Methods to Pause video when out of monitoring

I simply can’t appear to mix the 2 ideas to renew the right video. Any assist?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments