2013-07-31 36 views
0

我很努力地將一個YouTube視頻嵌入到我的Flash項目中,我無法在幾個小時後嘗試找到一個工作教程並學習api google提供。 我想要一個可以播放YouTube播放列表的播放器,目的是展示樂隊的現場表演,但我不知道如何讓它脫離地面!將youtube嵌入到動作腳本的Flash中3

如果任何人都可以提供幫助,將不勝感激。

謝謝! :)

回答

1
import flash.system.Security; 

Security.allowDomain('*'); 
Security.allowInsecureDomain('*'); 

var vPlayer:Object; 
var playerLoader:Loader; 

function loadVideo():void 
{ 
    playerLoader = new Loader(); 

    // next line loads a youtube player with no UI 
    playerLoader.load(new URLRequest('http://www.youtube.com/apiplayer?version=3')); 

    // wait for it to load 
    playerLoader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit); 
} 

function onLoaderInit(evt:Event):void 
{ 
    // 'vPlayer_container' is a movieclip on stage that you need to create to hold the youtube player. 
    // add your youtube Loader, (which is actually the player), to vPlayer_container's display list. 
    vPlayer_container.addChild(playerLoader); 

    // set the vPlayer variable to be the loaded youtube player 
    vPlayer = playerLoader.content; 

    // wait for it to be ready 
    vPlayer.addEventListener('onReady', onPlayerReady); 
} 

function onPlayerReady(evt:Event):void 
{ 
    vPlayer.removeEventListener('onReady', onPlayerReady); 

    // set listener for onComplete and play/pause events 
    vPlayer.addEventListener('onStateChange', onPlayerStateChange); 

    // mute it on start if you want 
    vPlayer.mute(); 

    // set size of video screen 
    vPlayer.setSize(392,220); 

    // now load your youtube video in your new youtube player 
    // get this video number off the url to your youtube video 
    vPlayer.loadVideoById('GEghz32qhiA', 0); 
} 

function onPlayerStateChange(evt:Event):void 
{ 
    // if video is over 
    if(Object(evt).data == 0) 
    { 
     //do something when video is over 
    } 
} 

// other player commands available - you need to make your own buttons for these 
// vPlayer.mute(); 
// vPlayer.unMute(); 
// vPlayer.pauseVideo(); 
// vPlayer.playVideo(); 

// to start the whole process, call loadVideo(); 
+0

感謝您的答案,我已經把代碼,但不幸的是它說在程序結束時意外的右大括號,當我擺脫了那個括號它說意外的結束程序,上午我錯過了什麼?謝謝! – user1892540

+0

它可能來自onPlayerChange()方法。我編輯它。用新方法嘗試一下。此外,當我從內存中寫入代碼時,此代碼可能無法正常運行,這只是爲了讓您開始。所有你需要的作品都在那裏。如果你足夠了解as3的語法,你應該可以將它們拼湊在一起。 – Ribs