Using MPMoviePlayerController as Texture in SceneKit

I created a cube in a script and tried to use an instance of MPMoviePlayerController as my material. This kindly works, but not quite good: the video seems very nervous, as if it will jump between video frames (mostly reproducing frames from the beginning to the last point). The sound is fine.

I did a short review of what is happening, I think it can be seen from the video: Youtube vid

This is the code that handles the display of the cube and the creation of the player:

var moviePlayer: MPMoviePlayerController?

func startPlayingVideo(){
    let mainBundle = NSBundle.mainBundle()
    let url = mainBundle.URLForResource("Sample", withExtension: "m4v")
    moviePlayer = MPMoviePlayerController(contentURL: url)

    if let player = moviePlayer{
        /* Listen for the notification that the movie player sends us whenever it finishes playing */
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "videoHasFinishedPlaying:", name: MPMoviePlayerPlaybackDidFinishNotification, object: nil)
        println("Successfully instantiated the movie player")
        player.scalingMode = .AspectFit

        var materials = [SCNMaterial]()
        for i in 1...6 {
            let material = SCNMaterial()
            material.diffuse.contents = player.view.layer
            player.view.frame = CGRectMake(0, 0, 200, 200)
            materials.append(material)
        }
        boxGeometry.materials = materials

        player.controlStyle = MPMovieControlStyle.None
        player.play()
    }
    else {
        println("Failed to instantiate the movie player")
    }
}

Any ideas how to fix this frame jump and why is this happening? Many thanks

+2
source share
1

radar , AVPlayerLayer SceneKit ( ... !). Apple , , , , :

AVPlayerLayer . SKVideoNode.

+5

Source: https://habr.com/ru/post/1654884/


All Articles