Twitter <%=Resources.labels.subscribe %>

Embed YouTube Videos Inside A Flex Application

  • 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.

    Tags:

    Permalink |

Comments (8) -
Leon Belenky
Leon Belenky United States
1/3/2009 10:22:34 AM #

Thanks for the tip on embedding YouTube videos inside Flex!

Reply

Jet Spice Games
Jet Spice Games
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.

Reply

Tex
Tex France
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

Reply

arun
arun India
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

Reply

anirudh
anirudh United States
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...

Reply

Brent
Brent United States
2/12/2009 3:04:04 PM #

There's a new API for YouTube and ActionScript 3/Flex:

http://code.google.com/p/tubeloc/

Reply

Leon Belenky-Dedicated Servers
Leon Belenky-Dedicated Servers United States
3/30/2009 12:25:38 AM #

This tip works great, thanks so much for sharing it!

Reply

Leon Belenky-Dedicated Servers
Leon Belenky-Dedicated Servers United States
4/28/2009 12:45:10 PM #

I am enjoying adding videos to the Flex Application-thanks again for this tip!

Reply

Pingbacks and trackbacks (3)+

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Intro

My name is Brent Lamborn. I´m 35 years old and I live in Nebraska. I've been coding with the .NET Framework since 2003. I'm a former Marine and I have 5 boys.


View Brent Lamborn's LinkedIn profileView Brent Lamborn's profile

Sponsored By

Categories

Tag Cloud

Blog Roll