A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: playing a YouTube video

Threaded View

  1. #1
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632

    playing a YouTube video

    Google has released the AS3 API for YouTube.
    This means you can embed a chromeless player now inside your AS3 based KoolMoves project. Here's an example
    Code:
    var player:Object;
    
    var yt_loader:Loader = new Loader();
    yt_loader.contentLoaderInfo.addEventListener(Event.INIT, onYTLoaderInit);
    yt_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
    
    function onYTLoaderInit(e:Event):void {
    
        // position the loader that contains the youtube player at (20, 20)
        
        yt_loader.x = 20;
        yt_loader.y = 20;
        addChild(yt_loader);
        
        // set the event listeners
        
        player = yt_loader.content;
        player.addEventListener("onReady", onPlayerReady);
        player.addEventListener("onError", onPlayerError);
    
    }
    
    function onPlayerError(e:Event):void {
        trace("player error:", e.data);
    }
    
    function onPlayerReady(e:Event):void {
    
    	// setup the player
    
    	player.setSize(320, 240);
    	player.setVolume(70);
    	
    	// load the video
    	// replace the first parameter with your own video id
    	
    	player.loadVideoById("AnWkTRnUuTU", 0, "default");
    
    }
    For the complete API reference, see http://code.google.com/intl/nl/apis/...reference.html
    Last edited by w.brants; 10-15-2009 at 09:22 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center