Невозможно увидеть видео в фоновом режиме сцены с комплектом сцены - PullRequest
0 голосов
/ 26 июня 2019

Я пытаюсь запустить 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
    }
}

}

Вот что я вижу, когда открываю приложение:

enter image description here

Любая помощь будет принята с благодарностью, ура!

1 Ответ

1 голос
/ 26 июня 2019

Это выполняется в iOS Simulator, который использует OpenGL, как показано на панели статистики. В Xcode 11 и macOS Catalina он будет использовать металлический рендер, и вы должны увидеть видео.

Если вы запустите приложение на реальном устройстве, видео также должно появиться.

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

API rendersContinuously немного лучше для достижения того же эффекта, поскольку он не относится к анимациям неявным образом.

...