在SceneKit中使用MPMoviePlayerController作为纹理 [英] Using MPMoviePlayerController as texture in SceneKit

查看:80
本文介绍了在SceneKit中使用MPMoviePlayerController作为纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在scenekit中创建了一个多维数据集,并尝试使用MPMoviePlayerController的实例作为其材质。它很有用,但效果不是很好:视频看起来很跳跃,就像在视频帧之间跳跃一样(基本上是从开始到最后一点播放的帧重放)。声音还可以。

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.

我对正在发生的事情做了一个简短的屏幕截图,我想从视频中可以看出这一点: Youtube vid

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

推荐答案

我打开了一个雷达不能用作SceneKit纹理(在设备上...适用于模拟器!)。 Apple很友好地回复说这是按预期工作的,并提供了另一种选择:

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在设备上被渲染出来并且不能用作纹理。请改为使用SKVideoNode。

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

这篇关于在SceneKit中使用MPMoviePlayerController作为纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆