带有Action Script 3的Youtube API

时间:2012-12-10 18:05:22

标签: actionscript-3 youtube-api

我有一个flash横幅,其中嵌入了youtube视频。当用户按下按钮时,横幅转到特定帧并播放视频。我需要它做的是,在视频结束后,它转发到另一帧。

我用来播放YouTube视频的AS3如下:

stop();

var player:Object;

Security.allowDomain("www.youtube.com");

var vidctn:Loader = new Loader();
vidctn.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
vidctn.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);

function onLoaderInit(e:Event):void{
addChild(vidctn);
player = vidctn.content;
player.addEventListener("onReady", onPlayerReady);
}

function onPlayerReady(e:Event):void{
player.destroy();
addChildAt(vidctn,0);
player.setSize(304,173);
player.x = 0;
player.y = 40;
player.mute();
player.loadVideoById("Dzz6lUsF19g",0,"large");
}

我想我需要一个eventlistener,可能是Event.COMPLETE,但我似乎无法想出一个。

1 个答案:

答案 0 :(得分:0)

这些是youtube api的状态(你只需要YT_ENDED,但很高兴拥有所有):

        public static var YT_UNSTARTED:int = -1;
        public static var YT_ENDED:int = 0;
        public static var YT_PLAYING:int = 1;
        public static var YT_PAUSED:int = 2;
        public static var YT_BUFFERING:int = 3;
        public static var YT_CUED:int = 5;

添加一个监听器:

        vidctn.contentLoaderInfo.addEventListener("onStateChange", onPlayerStateChange);

这是函数:

        protected function onPlayerStateChange(event:Event):void {
            trace("youtubePlayer: player state:", Object(event).data);
            if(Object(event).data==YT_ENDED) {
                   //here you can do your stuff
            }
       }