2012-01-19 42 views
3

This website列出了与youtube视频进行通信的youtube API函数。有人知道我可以在哪里找到他们的实施?我试图找出传递给SetVariable()以直接与youtube swf文件进行通信的内容。Youtube API函数

回答

2
package 
{ 
    import flash.display.DisplayObject; 
    import flash.display.Loader; 
    import flash.display.Sprite; 
    import flash.events.Event; 
    import flash.net.URLRequest; 

    public class Main extends Sprite 
    { 
     private var _loader : Loader; 
     private var _player : Object; 

     public function Main() 
     { 
      _loader = new Loader(); 
      _loader.contentLoaderInfo.addEventListener(Event.INIT, _onLoaderInit, false, 0, true); 
      _loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3")); 
     } 

     private function _onLoaderInit(event : Event) : void 
     { 
      _player = _loader.content; 
      _player.addEventListener("onReady", _onPlayerReady, false, 0, true); 
      addChild(DisplayObject(_player)); 

      _loader.contentLoaderInfo.removeEventListener(Event.INIT, _onLoaderInit); 
      _loader = null; 
     } 

     private function _onPlayerReady(event : Event) : void 
     { 
      _player.removeEventListener("onReady", _onPlayerReady); 
      // Once this event has been dispatched by the player, we can use 
      // cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl 
      // to load a particular YouTube video. 
      _player.setSize(640, 360); 
      _player.loadVideoById("D2gqThOfHu4"); 
     } 
    } 
    } 

,如果你想使用的控件从YouTube你只需要更换一个行:

//_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3")); 
//replace this line with the following 

_loader.load(new URLRequest("http://www.youtube.com/v/VIDEO_ID?version=3")); 
//replace VIDEO_ID with the id of the video you want to load in the previous case :"D2gqThOfHu4" 

//also you can comment the following line if you don't want the video to start automatically: 
    _player.loadVideoById("D2gqThOfHu4");