The YouTube video player is currently written in ActionScript 2.0 and integrating it into an AIR application requires a few additional steps. There are many solutions available that reverse engineer the URL to get access to the source video FLV, however, this breaks the terms of service and is not officially supported by YouTube or the API.
Next we will use the SWFObject to load in the YouTube Chromeless video player. Notice the use of wmode: “opaque” in this example. Without this you will not be able to place any display objects above your videos.
ActionScript Used to Load and Control the Video:
public class JSVideoPlayer extends Sprite
private var _html:HTMLLoader;
private var _ready:Boolean = false;
public function JSVideoPlayer()
_html = new HTMLLoader();
_html.paintsDefaultBackground = false;
_html.width = 400;
_html.height = 300;
this.addChild( _html );
public function loadNewVideo(videoID:String):void
public function playVideo():void
public function pauseVideo():void
private function onComplete (e:Event):void
_ready = true;
public function loadHTMLcontent():void
One of the limitations of using the HTMLLoader class is the inability to set the opacity of the video. For example you if wanted to fade the video out you would have to capture the current state of the video and replace it with a bitmap image that would then be faded out (download the zip file to see an example of this).
- YouTube Chromeless Player Example page google.api
PS: This example is only for AIR and may not work for Flex applications deployed on websites. Please visit ‘YouTube in Flex applications’ (On The Other Hand) for an example of how to do this in Flex.
This was originally posted on blackcj.com, Chris Black’s personal blog. Chris is a Senior Developer at Sierra Bravo.