ARKit

教學連結

// Load video and create video player
let videoPlayer : AVPlayer = {
    // Load cat video from bundle
    guard let url = Bundle.main.url(forResource: "video",   withExtension: "mp4") else {
        print("Could not find video file.")
        return AVPlayer()
    }
    return AVPlayer(url: url)
}()
let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)

plane.firstMaterial?.diffuse.contents = videoPlayer
self.videoPlayer.play()
// Instantiate the audio source
audioSource = SCNAudioSource(fileNamed: "fireplace.mp3")!
// As an environmental sound layer, audio should play indefinitely
audioSource.loops = true
// Decode the audio from disk ahead of time to prevent a delay in playback
audioSource.load()
// Create a player from the source and add it to `objectNode`
objectNode.addAudioPlayer(SCNAudioPlayer(source: audioSource))

Last updated