AVPlayerLayer作为SCNMaterial无法呈现,音频播放正常 [英] AVPlayerLayer as SCNMaterial not rendered, audio playing fine
问题描述
我正在尝试使用AVPlayerLayer作为要分配给SCNSphere的SCNMaterial.
i'm trying to use a AVPlayerLayer as a SCNMaterial to be assigned to a SCNSphere.
我创建了一个播放器,创建了一个播放器图层,并尝试使用和不使用backgroundLayer为我的SCNSphere分配材质
I create a player, create a player layer and have tried with and without a backgroundLayer to assign as material for my SCNSphere
问题是,我在这里得到了相同的结果报告: SCNMaterialProperty不渲染层
Issue is, I get the same result reported here: SCNMaterialProperty not rendering layer
音频播放,视频完全不显示!
Audio plays, video not rendered at all!
代码很简单:
// 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]
如上所述,无论我是否使用backgroundLayer:CALayer并将playerLayer添加为子图层,都会得到相同的结果.
As mentioned, whether I use a backgroundLayer : CALayer and add the playerLayer as a sublayer gives the same result.
感谢您的帮助
推荐答案
在最新版本的SceneKit中,不需要使用SKScene
和SKVideoNode
.您可以直接将AVPlayer
设置为SCNMaterialProperty
实例的内容.
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.
这篇关于AVPlayerLayer作为SCNMaterial无法呈现,音频播放正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!