AVPlayerLayer as SCNMaterial not rendered, audio playing fine

╄→гoц情女王★ 提交于 2019-12-12 10:43:30

问题


i'm trying to use a AVPlayerLayer as a SCNMaterial to be assigned to a SCNSphere.

Based on: https://developer.apple.com/library/mac/samplecode/SceneKit_Slides_WWDC2013/Listings/Scene_Kit_Session_WWDC_2013_Sources_Slides_ASCSlideMaterialLayer_m.html

I create a player, create a player layer and have tried with and without a backgroundLayer to assign as material for my SCNSphere

Issue is, I get the same result reported here: SCNMaterialProperty not rendering layer

Audio plays, video not rendered at all!

The bit of code is quite simple:

    // video player
    let path = NSBundle.mainBundle().pathForResource("tb", ofType: "mp4")
    let url  = NSURL(fileURLWithPath: path!)
    let player = AVPlayer(URL: url)             // AVPlayer
    player.actionAtItemEnd = .None
    player.play()

    let frame = CGRectMake(0, 0, 300, 300)

    let playerLayer = AVPlayerLayer()
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
    playerLayer.frame = frame
    playerLayer.player = player


    sceneMaterial = SCNMaterial()
    sceneMaterial.specular.contents = UIColor.whiteColor()
    sceneMaterial.shininess = 0.5
    sceneMaterial.diffuse.contents = playerLayer
    sphere.materials = [sceneMaterial]

As mentioned, whether I use a backgroundLayer : CALayer and add the playerLayer as a sublayer gives the same result.

Any help is appreciated


回答1:


@Guig @Byron, take a look at SKVideoNode. I had to use sprikeKit + SceneKit to get what i wanted done




回答2:


In recent versions of SceneKit using a SKScene and a SKVideoNode is not necessary. You can directly set the AVPlayer as the contents of a SCNMaterialProperty instance.



来源:https://stackoverflow.com/questions/33415651/avplayerlayer-as-scnmaterial-not-rendered-audio-playing-fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!