/**
* Copyright siouxcitizen ( http://wonderfl.net/user/siouxcitizen )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dpQt
*/
// forked from nijitaro's Youtube ActionScript 3.0 API テスト
/**
* Youtube動画を連続再生できるか試してみました
*
* Youtubeの動画IDをベタ書きで配列に設定して連続再生しています
* Youtubeと連携してる?VEVO?というサービス?のYoutube上動画のIDを配列にして設定しています
* Aerosmithの公式?PV動画リストを再生します
* 問題ありそうなら削除します
*
* ↓参考にさせて頂いたコード&サイト
* Youtube ActionScript 3.0 API テスト(Fork元です)
* http://wonderfl.net/c/vT3j
* YouTubePlayer API
* http://wonderfl.net/c/r5kL
* YouTube ActionScript 3.0 Player API リファレンス
* http://code.google.com/intl/ja/apis/youtube/flash_api_reference.html
*/
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.Security;
[SWF(backgroundColor="0x000000", frameRate="30", width="640", height="400")]
public class Index extends Sprite {
private var player:Object;
private var loader:Loader;
private var movieIdListIndex:int = 0;
private const movieIdList:Array = [
"NMNgbISmF4I", //Crazy
"qfNmyxV2Ncw", //Cryin'
"CBTOGVb_cQg", //Angel
"zSmOvYzSeaQ", //Amazing
"h3Yrhv33Zb8", //Love In An Elevator
"o-0lAhnoDlU", //Eat The Rich
"RqQn2ADZE1A", //Janie's Got A Gun
"7nqcL0mjMjw", //Livin' On The Edge
"nf0oXY4nDxE", //Dude (Looks Like A Lady)
"zkGfPrst29Y", //The Other Side
"CSnuQcFgvDo" //What It Takes
];
/// init
public function Index() {
loader = addChild(new Loader()) as Loader;
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit, false, 0, true);
loader.x = 150;
loader.y = 50;
//loader.load(new URLRequest("http://www.youtube.com/v/NMNgbISmF4I?version=3&enablejsapi=1")); //Youtubeコントローラー付き 最初はといあえずののIdを設定
loader.load(new URLRequest("http://www.youtube.com/v/NMNgbISmF4I?version=3")); //Youtubeコントローラー付き 最初はといあえずののIdを設定
}
/// events
private function onLoaderInit(event:Event):void {
loader.content.addEventListener("onReady", onPlayerReady);
loader.content.addEventListener("onError", onPlayerError);
loader.content.addEventListener("onStateChange", onPlayerStateChange);
loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);
}
private function onPlayerReady(event:Event):void {
// Event.data contains the event parameter, which is the Player API ID
// Once this event has been dispatched by the player, we can use
// cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl
// to load a particular YouTube video.
player = loader.content;
//player.setSize(640, 360);
player.setSize(352, 230);
//player.loadVideoById("NMNgbISmF4I", 0, "default"); //Crazy
//player.loadVideoById("qfNmyxV2Ncw", 0, "default"); //Cryin'
//player.loadVideoById("CBTOGVb_cQg", 0, "default"); //Ange
//ect...
player.loadVideoById(movieIdList[movieIdListIndex], 0, "default"); //1曲目「Crazy」再生
}
private function onPlayerError(event:Event):void {
// Event.data contains the event parameter, which is the error code
}
private function onPlayerStateChange(event:Event):void {
// Event.data contains the event parameter, which is the new player state
//プレイヤーの状態を判定
//未開始(-1)、終了(0)、再生中(1)、一時停止中(2)、バッファリング中(3)、頭出し済み(5)
if (Object(event).data == "0") { //動画が終了した場合
movieIdListIndex++;
if(movieIdListIndex > movieIdList.length - 1) return; //動画IDリストを超えた場合は処理を行わない
player.loadVideoById(movieIdList[movieIdListIndex], 0, "default");
}
}
private function onVideoPlaybackQualityChange(event:Event):void {
// Event.data contains the event parameter, which is the new video quality
}
}
}