2013-07-31 35 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