27 July 2010 14 Comments

Adding Flash or Youtube Video Using FBML

close

To embed a hosted Flash file or YouTube video to an FBML application or Static FBML tab, you must use the FBML code. Regular HTML embed code will not work. Fortunately, the FBML code is actually simpler and less confusing than standard embed code.

fb:swf and fb:flv

The two primary tags you would use to embed video or Flash files are <fb:swf> and <fb:flv>. Although they are very similar, it’s important to figure out which of the two are appropriate for your situation.

If you’re embedding a video from YouTube, or if you’re hosting your own swf file, use <fb:swf>.

Example:

<fb:swf
swfbgcolor="000000"
imgstyle="border-width:3px; border-color:white;"
swfsrc='http://www.youtube.com/v/xxxxxxxxxx'
imgsrc='http://img.youtube.com/vi/xxxxxxxxxx/2.jpg'
width='340' height='270' />

Embedding a YouTube Video

In the example above, the xxxxxxxxx is a placeholder for the YouTube video ID. You can obtain this video ID by looking at the url of the video on YouTube.

In the url http://www.youtube.com/watch?v=-CVYOCMpJRY, we can see by the url that the video ID is -CVYOCMpJRY.

The string of text immediately following the v= in a YouTube url is the video ID, and this is what you use in place of xxxxxxx in the example.

You’ll notice a parameter called imgsrc in the code example. This specifies what static image you wish to display when the video is loaded but has not been played yet. YouTube automatically generates static images based off the uploaded video, so you can use one of their, or upload your own and specify the url to that image in the imgsrc parameter.

To embed your own swf file, simply swap out the entire swfsrc and imgsrc values above with the url to your own files. While most of the other parameters are self-explanatory, and deal with background colors, size and and borders, you can check out the full documentation on fb:swf for more detail.

Embedding an flv file

If you need to embed an .flv file, facebook provides FBML for that as well. Although this code is arguably not used as often as <fb:swf>, <fb:flv> can be very useful.
Example:

<fb:flv src='http://www.mediacollege.com/video-gallery/testclips/barsandtone.flv'
width='400' height='300' title='my movie'
color='#FFBB00' salign='r'
img='http://www.example.com/test.jpg'
scale='showall'/ >

Again, the additional parameters are fairly self-explanatory, but you can find the documentation here.

Possibly Related posts:

  • Pingback: Using JW Player in FBML to Bypass YouTube Video Ads | FBMHell.Com

  • joe

    Hi there, loving your work… any idea on how to embed a Flixtime movie into FBML?

  • drcom

    how might one go about swapping fb:flv’s src attribute with a new url-to.flv without refreshing the page using fbjs? trying to create a small carousel to browse and play different vids inside an fbml canvas page. thanks!

  • http://www.snipe.net snipe

    Have you checked out the carousel code?
    http://fbmhell.com/2010/08/facebook-fbjs-fbml-image-carousel/

    In something like that, you’re not actually swapping the fb:flv src url, you’re actually swapping out divs that contain different fb:flv tags.

  • Parthibalo

    Hi! its not work.

    what is my mistake please help.

    • http://www.snipe.net snipe

      Please be more specific. “Its not work” doesn’t tell me anything about what you’re seeing, any applicable error messages, etc. Also, please paste your code into pastebin.com – the comment system mangles code.

  • http://habitza.com/ deenalev

    thank you thank you thank you.

  • Anders Cumuli

    Hey
    Is it possibel to load the youtube right away… after clicking the image… its a little funnt that it shows the image . and then the user have to click play again

    • http://www.snipe.net snipe

      Not on a tab. I think I mentioned that FB blocks autoloading of Flash on FBML tabs, although that may change when they switch over to iframes.

  • Greedelle

    Yes, just add &autoplay=1 after your embed code ex. swfsrc = ‘http://www.youtube.com/v/JOt2Qp0H9G8&autoplay=1

  • Anonymous

    Hi, How about if we put a megavideo video in FBML? is it possible??? Because I want to Put a movie in my page… thanks!!

  • Gorden

    I am working on facebook application, where user will input different video embed code and I require showing that videos (embed code) using FBML. I don’t want to use as all video size can be different. so iframe won’t able to display bigger width video.

    Please help me out.

  • http://twitter.com/JeffersonFaudan Jefferson Faudan

    for no apparent reason this codes do not work with FB… i wonder why…

  • Mohammad Kalim

    thanks nice work