Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
768 views
in Technique[技术] by (71.8m points)

ios - Using MPMoviePlayerController as texture in SceneKit

I created a cube in scenekit and tried to use an instance of an MPMoviePlayerController as its material. It kind-ish works but not exactly well: the video seems to be very jumpy, like it would be jumping between the video frames (basically replaying frames from the beginning till the last point played). The sound is ok.

I made a short screencapture of what's happening, I guess it is obvious from the video: Youtube vid

This is the code that handles the mapping to 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-jumping and why it occurs? Thanks a lot

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I opened a radar about AVPlayerLayer not working as a SceneKit texture (on device... works on simulator!). Apple was kind enough to reply saying this was working as intended, and supplied an alternative:

AVPlayerLayer are rendered out of process on the device and can’t be used as a texture. Please use a SKVideoNode for this instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...