我正在尝试使用sceneKit
在我的场景背景中运行mp4。该视频似乎正在通过打印语句和状态栏(约50 fps)执行。但是,当应用程序在模拟器上打开时,我看到的只是黑屏。我可以使视频在典型的AVPlayer
中运行,但是我不知道如何将其与Scene Kit连接。
这是我的代码:
import UIKit
import AVKit
import SceneKit
class GameViewController: UIViewController {
var sceneView: SCNView!
//var scene: SCNScene!
var cameraNode: SCNNode!
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
//sceneView.delegate = self
sceneView = self.view as! SCNView
// Show statistics such as fps and timing information
sceneView.showsStatistics = true
// Create a new scene
let scene = SCNScene()
// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
// Set the scene to the view
sceneView.scene = scene
let movieFileURL = Bundle.main.url(forResource: "master", withExtension: "mp4")!
let player = AVPlayer(url:movieFileURL)
scene.background.contents = player
sceneView.play(nil) //without this line the movie was not playing
player.play()
}
override var shouldAutorotate: Bool {
return false
}
override var prefersStatusBarHidden: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return .allButUpsideDown
} else {
return .all
}
}
}
这是我打开应用程序时看到的:
任何帮助将不胜感激,欢呼!
答案 0 :(得分:1)
这正在iOS模拟器中运行,该模拟器使用OpenGL,如统计信息栏中所示。在Xcode 11和macOS Catalina中,它将使用Metal渲染器,您应该会看到视频。
如果您在实际设备上运行该应用,则视频也会出现。
sceneView.play(nil) //without this line the movie was not playing
rendersContinuously
API可以更好地达到相同的效果,因为它没有隐式地引用动画。