I've been trying to get this code that's pretty much copied/pasted from Apple's documentation to play a local video but seem to be missing something. I've imported AVFoundation and the video into the project. I'm not throwing any errors but no matter how I tweak am unable to see any video (on my device or simulator). I'm sure it's something simple but am clearly missing something. Please help! I'm running the latest version of IOS and Xcode.
var videoNode: SKVideoNode? = {
guard let urlString = Bundle.main.path(forResource: "Clouds", ofType: "mov") else {
print("You messed up son")
return nil
}
let url = URL(fileURLWithPath: urlString)
let item = AVPlayerItem(url: url)
let player = AVPlayer(playerItem: item)
return SKVideoNode(avPlayer: player)
}()
override func didMove(to view: SKView) {
addChild(worldNode)
videoNode?.position = CGPoint( x: frame.midX, y: frame.midY)
videoNode?.size.width = 1920
videoNode?.size.height = 1080
videoNode?.zPosition = 100
worldNode.addChild(videoNode!)
videoNode?.play()
}
After searching around awhile I thought I'd try removing the movie then going to Build Phases > Copy Bundle Resources. I then added my movie in this menu and after rebuilding it worked as expected. I'm guessing my copy of the movie into the project originally may have had issues. Anyway maybe this will help someone down the road.