Developing Adobe AIR / Flex – Simple Youtube player with “AirYouTube” library

In previous example I have implemented a simple player with tubeloc library, but when i use it for multiple youtube player application it doesn’t work as aspected! infact this library has problems with multiple istances of the component, so only one istance can be used and the “destroy” method doen’t free the istance…so i try to find something else.
For this purpose i found aroun the web “AirYouTube”, another good component library and i post here another simple application with a main player and a button tha open simultanusly another istance of player in a pop up window.
The library and example can be founded at blog.derhess.de

and this is my basic snippet of code:

main application:

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute

xmlns:youtube=”de.derhess.video.youtube.*

width=”599” height=”600>

<mx:Script>

<![CDATA[

import mx.managers.PopUpManager;

import de.derhess.video.youtube.AirYouTube;

import de.derhess.video.youtube.YouTubeAS3;

import flash.utils.getDefinitionByName;

import de.derhess.video.youtube.YouTubeError;

import de.derhess.video.youtube.YouTubePlayingState;

import mx.controls.Alert;

import mx.collections.ArrayCollection;

import de.derhess.video.youtube.YouTubeVideoQuality;

import de.derhess.video.youtube.YouTubeEvent;

private function handlePlayerLoaded(event:YouTubeEvent):void

{

youTubePlayer.cueVideoById(“paste_here_your_youtube_videoID_here”,0,YouTubeVideoQuality.DEFAULT);

}

public function apriPop():void{

var myPop:pop = new pop();

PopUpManager.addPopUp(myPop,this,true);

}

]]>

</mx:Script>

<mx:Button x=”387” y=”393” label=”Carica Video in Popup” click=”apriPop();”/>

<youtube:FlexYouTube id=”youTubePlayer

x=”330” y=”0

width=”320” height=”240

volume=”100

youtubePlayerLoaded=”{handlePlayerLoaded(event);}”

/>

</mx:WindowedApplication>

[adsense_id=”1″]

pop.mxml component:

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:Canvas xmlns:mx=”http://www.adobe.com/2006/mxml” width=”400” height=”300” xmlns:youtube=”de.derhess.video.youtube.*>

<mx:Script>

<![CDATA[

import de.derhess.video.youtube.AirYouTube;

import de.derhess.video.youtube.YouTubeAS3;

import flash.utils.getDefinitionByName;

import de.derhess.video.youtube.YouTubeError;

import de.derhess.video.youtube.YouTubePlayingState;

import mx.controls.Alert;

import mx.collections.ArrayCollection;

import de.derhess.video.youtube.YouTubeVideoQuality;

import de.derhess.video.youtube.YouTubeEvent;

private function handlePlayerLoaded2(event:YouTubeEvent):void

{

youTubePlayer2.cueVideoById(“paste_here_your_youtube_videoID_here”,0,YouTubeVideoQuality.DEFAULT);

}

]]>

</mx:Script>

<youtube:FlexYouTube id=”youTubePlayer2

x=”59” y=”234

width=”320” height=”240

volume=”100

youtubePlayerLoaded=”{handlePlayerLoaded2(event);}”

/>

</mx:Canvas>