Tech from Hel
Helene's ramblings on Wordpress, jQuery and other web technologies.
rss
twitter
  • About
  • Projects

Flv Videos in a Thickbox

9 comments
Posted on May 6 2008 by helene

Embedding Videos: Flv Videos in a Thickbox

NOTE: This is an updated version of an article I originally wrote on September 6, 2007 that was posted on SupernaturalStation.org.

Step-by-step instructions on how to display a flash video (.flv) inside a thickbox* using JW's Flvplayer

For those of you wondering how to implement JW's Flv player inside a Thickbox, it is actually quite simple. Here's how:

  1. If you don't already have them, download jquery and ThickBox 3 and add them to your page's head section

    jquery.js is available at docs.jquery.com/Downloading_jQuery. ThickBox 3.1 is a group of files and images (thickbox.js, thickbox-compressed.js, thickbox.css, loadingAnimation.gif, and macFFhack.png) located at jquery.com/demos/thickbox. Download all the Thickbox files and install them in a single common directory, “thickbox”, on your web server.

    In your document head, add javascript links to jquery.js and thickbox.js, a style link for thickbox.css, and a javascript variable definition that points to “loadinganimation.gif”, a graphic that displays when thickbox is slow to load.

     <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="thickbox/thickbox.js"></script>
    <script type="text/javascript"> var tb_pathToImage = "thickbox/loadingAnimation.gif";</script>
    <style type="text/css" media="screen">@import "thickbox/thickbox.css";</style>

    Note: If your web site is on a slow server or if you just want to keep your page load speed fast, you can replace jquery.js and thickbox.js with their faster loading, compressed versions, jquery-packed.js and thickbox-compressed.js, respectively.

  2. Next, download JW's Flv Player or Media Player and add the included swfobject.js file to your page head

    Flv Player (or Media Player) can be downloaded from www.jeroenwijering.com. Save the files, flvplayer.swf (or mediaplayer.swf) and swfobject.js, to your web server, then add a javascript link to swfobject.js in your page's head section

    <script type="text/javascript" src="swfobject.js"></script>

    Note: If page load speed is an issue, you can omit “swfobject.js” from the document head. swfobject.js is not actually used in this demo. It is only included because of the slight chance that Flv player has an internal reference to it.

  3. Then, in the body of your page create a hidden <div> with a unique id and embed the video there

    The <div> should have a unique id="onPageHiddenContent-20" and a style attribute of style=”display:none;” to keep it hidden until the viewer clicks on a link that you specify in step #4 below. Inside the <div>, place an <embed> tag to embed JW's Flv Player, flvplayer.swf, that you downloaded in step #2. List your flv video (myvideo_file.flv) and your video preview image (myvideo_image.jpg) as “flashvars” arguments in the embed tag. See JW's readme instructions for more details about embedding a video with flvplayer.swf.

    <div id="onPageHiddenContent-20" style="display:none;">
    <embed src="http://www.myfileserver.com/folder/flvplayer.swf"
        width="320" height="260" type="application/x-shockwave-flash" 
        pluginspage="http://www.macromedia.com/go/getflashplayer"
        flashvars="file=http://www.myfileserver.com/folder/myvideo_file.flv&image=http://www.myfileserver.com/folder/myvideo_image.jpg" />
    </div> 

    In the above code, change the url paths, rename myvideo_file.flv and myvideo_image.jpg to match your own video and adjust the height and width as needed. You will also want to make sure that height=video_height+20px to make room for the controller.

  4. Lastly, add a thickbox link element with class="thickbox" to display the video inside a thickbox

    Use the thickbox inline* anchor, "#TB_inline" for the "href" and include the thickbox dimensions (>=video size) and your hidden div id as query parameters. The link can surrounded any text or an image. See thickbox inline content instructions for more information.

    <a href="#TB_inline?height=270&width=320&inlineId=onPageHiddenContent-20"
       class="thickbox" title="My Video">Click here to see video</a>

And thats all there is to it folks! Simple, eh?

Here's the entire code in a sample web page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"><head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/thickbox/thickbox.js"></script>
<style type="text/css" media="screen">@import "js/thickbox/thickbox.css";</style>
<script type="text/javascript"> var tb_pathToImage = "thickbox/loadingAnimation.gif";</script>
<script type="text/javascript" src="js/swfobject.js"></script>
</head>
<body>
<h2>Flv Video in a Thickbox example</h2>
<div id="onPageHiddenContent-20" style="display:none;">
<embed src="http://www.myfileserver.com/folder/flvplayer.swf"
    width="320" height="260" type="application/x-shockwave-flash" 
    pluginspage="http://www.macromedia.com/go/getflashplayer"
    flashvars="file=http://www.myfileserver.com/folder/myvideo_file.flv&image=http://www.myfileserver.com/folder/myvideo_image.jpg" />
</div>
<a href="#TB_inline?height=270&width=320&inlineId=onPageHiddenContent-20"
class="thickbox" title="My Video">Click here to see video</a> </body> </html>

This method works in FF 1.5, FF 2, Safari 1**, Safari 3 beta, and IE 6. I have not tested it in other browsers, but it should work fine in any modern browser.

Click here to see a demo.

As for you purists out there, yes…”embed” is not xhtml compliant, but all modern browsers support it and that's more important to your site visitors.

**Note: Please note that Thickbox no longer works in Safari 1 when combined with any version of jquery greater than version 1.1.2 and the combination, jquery 1.1.3+thickbox3, actually causes Safari 1 to crash.

*Important Note: This “inline”, javascript-free method of embedding a flv video in a thickbox is appropriate for simple web pages with just a few videos. If your document has many videos or other flash content that affects z-index and transparency settings, an “inline” thickbox will be problematic, especially in IE. A better solution would be to embed your video in external document/popup player that you can open in a thickbox “iframe” instead.

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

  Tags: flv, thickbox, video embed Category: Multimedia

9 Comments

  1. Jason says:
    October 24, 2008 at 1:26 am

    Having a terrible issue with the thickbox(3.1)+swfobject(jwFlv): In Firefox2 Mac/PC I get a terrible flicker if I resize the browser window. The scrub bar looks like it has chunks taken out of it. Any thoughts?

    Reply
  2. Jason says:
    October 24, 2008 at 2:07 am

    ========////========

    Answered my own question: Firefox .onPageHiddenContent{opacity:1;} is required in order to not have the flicker issue I was experiencing. (Your demo on this page also could benefit from this as it too flickers :D )

    ========////========

    Here’s new one: I want to embed multiple videos on a single page. How is this accomplished. Per your other response to comment, there must be a separate embed file for each video…i have set this up (using swfobject(jwFlv)) established a separate “s” variable for each video,[s1, s2, s3, s4] and pointed each link to a coordinated {id=”vid_01″ , id=”vid_02″, id=”vid_03″, id=”vid_04″} HOWEVER. only the 1st video plays? And worse yet, this problem only occurs in Safari(Mac), IE6, FF2(Win).

    Any chance you could provide implicit instructions on how to set up multiple videos on a single page?

    Reply
  3. xsi says:
    January 3, 2009 at 12:35 pm

    thanks for your work, simple! (and happy new year)

    Reply
  4. iriney says:
    July 6, 2009 at 7:42 am

    I have a problem with multiple videos on one page.

    In IE6-IE8, when I switch from one to another video the previous ones keeps loading in background which results in major lag, and inability to view videos until previously activated ones load. Combination is swfobject, thickbox and jw player.

    <a href="#TB_inline?height=400&width=520&inlineId=video">View video ยป</a>

    I have 5 more links like this on one page, for different videos. Videos are in hidden layers and are called with thickbox function.

    Everything works fine in firefox.

    Reply
  5. jon says:
    December 2, 2009 at 6:04 pm

    Was using your technique and it works great except that if you click the link the movie displays and all is well, but if you close the thickbox, then click the link again…it doesnt play, you have to refresh the page. Any ideas? Thanks

    JOn

    Reply
  6. john says:
    February 8, 2010 at 2:57 am

    Hello,
    When i tried to play video my video palyed properly but my initial loading image doesn’t show even if i have given correct path. When i checked in IE it doen’t show cross image just directly open video in thickbox iwant loading image to display first then video pls help me…

    Reply
  7. helene says:
    February 9, 2010 at 11:48 pm

    John,
    There are 3 possible causes of your problem:
    1. image URI is wrong.
    2. javascript variable “tb_pathToImage” is missing or incorrect in document head.
    3. image is in a secure directory/location that is denying public access.

    You need to open the loading image directly in your browser. Enter the image URI in the location box. If you can’t open the image, then Thickbox can’t either. Move image to another location, if you need to.
    Also, look at your video page “View Source”. Check that javascript variable, “tb_pathToImage”, is defined within document <head> and have the correct uppercase/lowercase values for path/URI and variable name, as both are case sensitive.

    Reply
  8. helene says:
    February 10, 2010 at 6:59 am

    John,
    I reread your comment and if you were referring to the video “preview” image which displays after thickbox opens but before the video plays, then the problem is in your video player settings, not thickbox. You need to doublecheck and/or add to your video’s “flashvars” parameters in the <embed> tag, in that case.

    Reply
  9. manik says:
    March 11, 2010 at 1:37 am

    thanks its working

    Reply

Leave a Reply

Click here to cancel reply.




Categories

  • Blogging
  • javascript
  • Miscellaneous
  • Multimedia
  • MySQL
  • Plugins

Recent Posts

  • WassUp Works Well with WP Widget Cache
  • CTRL+Z Undo: The Keyboard Shortcut You Can’t Do Without
  • A Fine Fix for “get_currentuserinfo undefined”
  • Optimize with MySQL Procedure Analyse
  • Sleeping with Javascript

Popular Posts

  • Horizontal Submenus for Wordpress Admin Plugins
  • Flv Videos in a Thickbox
  • YouTube Videos in a Thickbox
  • Sleeping with Javascript
  • Installing a More Secure Wordpress

Archives

Ads


  • About
  • Projects
Powered by Wordpress  |  Designed by WebTreats