Я пытаюсь запустить mp4 в фоновом режиме моей сцены с sceneKit
.Похоже, что видео выполняется через операторы печати и строку состояния, показывающую ~ 50 кадров в секунду.Однако, когда приложение открывается на симуляторе, я вижу только черный экран.Я могу заставить видео работать в обычном 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
}
}
}
Вот что я вижу, когда открываю приложение:
Любая помощь будет принята с благодарностью, ура!