Last active
June 25, 2020 20:52
-
-
Save eospi/02875fa827c9b9b20c8982d3249fe90b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
@IBOutlet var arView: ARView! | |
var videoPlayer: AVPlayer! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
guard let path = Bundle.main.path(forResource: "myFileName", ofType: "mp4") else { return } | |
let videoURL = URL(fileURLWithPath: path) | |
let playerItem = AVPlayerItem(url: videoURL) | |
let videoPlayer = AVPlayer(playerItem: playerItem) | |
self.videoPlayer = videoPlayer | |
let videoMaterial = VideoMaterial(avPlayer: videoPlayer) | |
let videoPlane = ModelEntity(mesh: .generatePlane(width: 1.6, depth: 0.9), materials: [videoMaterial]) | |
let anchor = AnchorEntity(plane: .vertical) | |
anchor.addChild(videoPlane) | |
arView.scene.anchors.append(anchor) | |
videoPlayer.play() | |
NotificationCenter.default.addObserver(self, selector: #selector(loopVideo), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerItem) | |
} | |
@objc func loopVideo(notification: Notification) { | |
guard let playerItem = notification.object as? AVPlayerItem else { return } | |
playerItem.seek(to: CMTime.zero, completionHandler: nil) | |
videoPlayer.play() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment