I am using the SpriteKit to play video,this is my code to create the SKVideoNode from AVPlayer:
func CreateVideoViewWithAVPlayer(player:AVPlayer)
{
video = SKVideoNode(AVPlayer: player)
let frameLayer=AVPlayerLayer(player: player)
//video?. = CGRectMake(0, 0, 100, 100)
video?.size = CGSize(width: 1024, height: 768)
println(player.currentItem)
video?.anchorPoint = CGPoint(x: 0, y: 0)
video?.position = CGPoint(x: 0, y: 0)
backgroundColor = SKColor.blackColor()
self.addChild(video!)
}
And I create a AVPlayer give the function:
let scene01 = GameScene(size: view.bounds.size)
scene01.CreateVideoViewWithAVPlayer(player!)
But When I call this "player.play()" ,I just show the first frame and not going any more. but if I use the "video" in the "CreateVideoViewWithAVPlayer" function ,It can play.
Another: if I use this code"
skView.presentScene(scene01)
//self.view.addSubview(skView)
(Comments the second) And user "player.play()" it can play (I can hear the sound). But if I use this:
skView.presentScene(scene01)
self.view.addSubview(skView)
I also can see the first frame.and can not run anymore.
Is there something I do is wrong? Help Me! Thanks A lot.
For no reason. You just can't use AVPlayer to control SKVideoNode's play or pause. but you can control monitor its play state via AVPlayer.
To play or pause a SKVideoNode, you have to use
video.play() / video.pause() // (video you declared here is the instance of SKVideoNode)
来源:https://stackoverflow.com/questions/26541073/avplayer-play-skvideonode-video-i-just-can-not-control-the-playback