3

The following code shows my video file in correct zPosition with the other elements I'm working with, creating a background video.

The problem I'm having is that the vertical video (1080x1920 pixels) gets rotated 90 degrees counterclockwise, and is stretched to fit as a landscape video. How can I ensure correct orientation without sacrificing my need to use the SKVideoNode with zPosition?

let videoNode: SKVideoNode? = {

    guard let urlString = Bundle.main.path(forResource: "merry", ofType: "mov") else {
        return nil
    }

    let url = URL(fileURLWithPath: urlString)
    let item = AVPlayerItem(url: url)
    player = AVPlayer(playerItem: item)

    return SKVideoNode(avPlayer: player)

}()

videoNode?.position = CGPoint( x: frame.midX, y: frame.midY)
videoNode?.size = self.frame.size
videoNode?.zPosition = 20
addChild((videoNode)!)

player.play()
player.volume = 0

Many thanks!

Mr_P
  • 523
  • 2
  • 16

1 Answers1

5

Got there in the end with a workaround:

// fix to rotate vertical video by 90 degrees and resize to fit....
videoNode?.zRotation = CGFloat(-Double.pi) * 90 / 180
videoNode?.size.width = self.frame.size.height
videoNode?.size.height = self.frame.size.width
Mr_P
  • 523
  • 2
  • 16
  • HI, I followed this tutorial to play transparent video in SceneKit from SpriteKit. https://medium.com/@quentinfasquel/ios-transparent-video-in-spritekit-then-scenekit-2fc66b8706a6 but my video is coming in vertical how can i play it normally. you can check playground page-2 example same issue vertical video. – iOSDude Mar 02 '20 at 12:27
  • videoNode.yScale = -1.0. I did it to SKNode video size is playing properly but colour is completely faded come with white screen with some objects playing in it. – iOSDude Mar 02 '20 at 13:10