AVPlayer播放SKVideoNode视频,我就是无法控制播放 [英] AVPlayer play SKVideoNode video ,I just can not control the playback

查看:128
本文介绍了AVPlayer播放SKVideoNode视频,我就是无法控制播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SpriteKit播放视频,这是我从AVPlayer创建SKVideoNode的代码:

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!)
}

然后我创建一个AVPlayer赋予功能:

And I create a AVPlayer give the function:

        let scene01 = GameScene(size: view.bounds.size)
    scene01.CreateVideoViewWithAVPlayer(player!)

但是当我将其称为"player.play()"时,我只是显示第一帧而已,不再进行.但是,如果我在"CreateVideoViewWithAVPlayer"功能中使用视频",则可以播放.

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)

(评论第二个),并且用户"player.play()"可以播放(我可以听到声音). 但是,如果我使用这个:

(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.

推荐答案

无故.您只是无法使用AVPlayer来控制SKVideoNode的播放或暂停.但是您可以通过AVPlayer控制其播放状态.

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.

要播放或暂停SKVideoNode,您必须使用

To play or pause a SKVideoNode, you have to use

video.play() / video.pause() // (video you declared here is the instance of SKVideoNode)

这篇关于AVPlayer播放SKVideoNode视频,我就是无法控制播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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