Embed YouTube Videos Inside A Flex Application

23. December 2008

I recently ran across a question in a Flex forum from a visitor asking how to embed YouTube videos inside Flex . The solution is very simple. Since the YouTube player is a Flash object itself,  we can simply use the SWFLoader object to load the Youtube video into our Flex app. You just need to copy the embed code on the YouTube page for the video you want to embed in your application. It will look like this:

 

<object width="425" height="344"><param name="movie" 
value="http://www.youtube.com/v/zlfKdbWwruY&hl=en&fs=1">
</param><param name="allowFullScreen" value="true">
</param><param name="allowscriptaccess" value="always">
</param><embed src=http://www.youtube.com/v/zlfKdbWwruY&hl=en&fs=1
 type="application/x-shockwave-flash" 
allowscriptaccess="always" allowfullscreen="true" 
width="425" height="344"></embed></object> 
 
 

Then just grab the URL to the video from the embed code and use it as the source property for your SWFLoader.  I created a working sample here with view source enabled.

Adobe Flex

Comments

1/3/2009 10:22:34 AM #
Thanks for the tip on embedding YouTube videos inside Flex!
1/18/2009 6:09:38 PM #
Brent, you should get a medal for the Flex YouTube embedder. I didn't know it was that easy. There are a ton of outdated blogs out there.
Tex
1/25/2009 10:00:56 AM #
well, in fact it's not so simple... or just rename your post to "Embed ONE youtube video inside a Flex application".
Youtube SWF instance is not destroyed while removed or replaced so it's impossible to load another youtube video.
Actualy you'll have to create an AS2 bridge through LocalConnection to control youtube AS2 SWF from AS3 Flex application and make it destroyed.

more infos here : apiblog.youtube.com/.../...er-christmas-story.html
arun
arun
2/4/2009 6:26:19 AM #
hi,its easy to use,but how can we play list of two or three videos using this,is it possible to do that,please help me
anirudh
anirudh
2/8/2009 5:01:25 PM #
Try resizing it to 200 * 160 or something like on a side.. thats when it gets ugly with content outside the loader...
2/12/2009 3:04:04 PM #
There's a new API for YouTube and ActionScript 3/Flex:

http://code.google.com/p/tubeloc/
3/30/2009 12:25:38 AM #
This tip works great, thanks so much for sharing it!
4/28/2009 12:45:10 PM #
I am enjoying adding videos to the Flex Application-thanks again for this tip!
12/8/2009 4:14:45 AM #
Pingback from groups.jonzu.com

Html embed in flex : 59597
12/25/2009 1:40:39 PM #
Pingback from moviesberry.com

The Devil's Mercy, 2008
5/20/2010 1:11:10 PM #
Pingback from 374.myipgirl.com

Royal Decameron Montego Beach 3 Star, Used Sale 2004 Mercury Montego
Comments are closed