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 |