AVPlayer play SKVideoNode video ,I just can not control the playback

房东的猫 提交于 2019-12-23 01:29:13

问题


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.


回答1:


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

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