0

I made an app that allows you to scan an image with an ios device and it plays a video using arKit tracking . However, once the video is finished, I can't seem to find a way to make it restart . Is there anyway I can recall all the code in the viewcontroller?

if let imageAnchor = anchor as? ARImageAnchor {
    // Create a plane
    let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)
    if imageAnchor.referenceImage.name == "skateboard" {
        // Set AVPlayer as the plane's texture and play
        plane.firstMaterial?.diffuse.contents = self.SkateboardVideoPlayer
        self.SkateboardVideoPlayer.play()
    }
}
Malik
  • 3,763
  • 1
  • 22
  • 35
moe safar
  • 140
  • 2
  • 17

1 Answers1

-1

Have you tried looping the video with a notification observer? See the below code from here:

var SkateboardVideoPlayer: AVPlayer!

// In viewDidLoad or similar method
...

NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: self.SkateboardVideoPlayer.currentItem, queue: .main) { [weak self] _ in
    self?.SkateboardVideoPlayer?.seek(to: CMTime.zero)
    self?.SkateboardVideoPlayer?.play()
}
dsringari
  • 104
  • 2