我试图在sceneKit场景的背景下运行mp4。视频似乎是通过打印语句执行的&状态栏显示大约50 fps。但是当应用程序在模拟器上打开时-我看到的只是一个黑屏。我可以让视频在典型的AVPlayer中运行,但我不知道如何将其与场景工具包连接起来。
这是我的代码:

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
    }
}

}

这是我打开应用程序时看到的:
ios - 使用场景工具包无法在场景背景中看到视频-LMLPHP
任何帮助都将不胜感激,干杯!

最佳答案

这是在iOS模拟器中运行的,它使用OpenGL,如统计栏中所示。在Xcode 11和macOS Catalina中,它将使用金属渲染器,您应该可以看到视频。
如果在实际设备上运行应用程序,则还应显示视频。

sceneView.play(nil) //without this line the movie was not playing

为了达到同样的效果,rendersContinuouslyAPI稍微好一点,因为它没有隐式地引用动画。

关于ios - 使用场景工具包无法在场景背景中看到视频,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56770200/

10-12 15:08