2009年12月29日 星期二

[AS2] Flash載入youtube影音,包含其播放介面

[Flash 8][AS2] 載入youtube影音,包含其播放介面
由Google Code提供的Youtube API資訊, 得知在AS2可以這麼做.



swf預覽


第一影格AS2

// create a MovieClip to load the player into
var ytplayer:MovieClip = _root.createEmptyMovieClip("ytplayer", 1);

// create a listener object for the MovieClipLoader to use
var ytPlayerLoaderListener:Object = {
onLoadInit: function() {
// When the player clip first loads, we start an interval to
// check for when the player is ready
loadInterval = setInterval(checkPlayerLoaded, 250);
}
};

var loadInterval:Number;

function checkPlayerLoaded():Void {
// once the player is ready, we can subscribe to events, or in the case of
// the chromeless player, we could load videos
if (ytplayer.isPlayerLoaded()) {
ytplayer.addEventListener("onStateChange", onPlayerStateChange);
ytplayer.addEventListener("onError", onPlayerError);
clearInterval(loadInterval);
}
}

function onPlayerStateChange(newState:Number) {
trace("New player state: "+ newState);
}

function onPlayerError(errorCode:Number) {
trace("An error occurred: "+ errorCode);
}

// create a MovieClipLoader to handle the loading of the player
var ytPlayerLoader:MovieClipLoader = new MovieClipLoader();
ytPlayerLoader.addListener(ytPlayerLoaderListener);

// load the player.取Youtube影音網址黃色部份,並捨去&及其後面的字碼;
// http://www.youtube.com/watch?v=YCJ74E2wH8s&feature=rec-fresh+div-r-1-HM
//http://www.youtube.com/v/貼在這裡. <---前面網址固定不變. ytPlayerLoader.loadClip("http://www.youtube.com/v/YCJ74E2wH8s", ytplayer);

swf
http://sites.google.com/site/terfict3/home/981229_fl8_as2_youtube.swf

fla
http://sites.google.com/site/terfict3/home/981229_fl8_as2_youtube.fla

如此, 或許也可把Youtube影音當賀卡之類的來寄送,當然收件方要有Flash獨立播放器
※  Download the Windows Flash Player 10 Projector content debugger (EXE, 5.18 MB)
→ 名稱有
Projector字眼,就是Flash獨立播放器,可直接播放swf檔 

1 則留言:

匿名 提到...

好像失效了?我需要2.0的說...