2012-01-19 17 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");