Issues with vertical video orientation in SKVideoNode using Swift

柔情痞子 提交于 2019-12-23 23:24:50

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/48348368/issues-with-vertical-video-orientation-in-skvideonode-using-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!