Wednesday, June 9, 2010

JW Player on Fancybox

Using the advise from this thread, here's how I got JW Player working inside FancyBox (to play FLV files in a lightbox):

<a id="viewflv" href="js/player.swf?file=video.flv&amp;autostart=1"
title="Test Flv">Click to view FLV video</a>
<script type="text/javascript"> //<![CDATA[
$(function() {
$("#viewflv").click(function() {
$.fancybox({
'autoscale' : false,
'transitionIn' : 'none',
'transitionOut': 'none',
'padding' : 0,
'title' : this.title,
'width' : 370,
'height' : 301,
'type' : 'swf',
'href' : this.href,
'swf' : { 'wmode':'transparent', 'allowfullscreen':'true' }
});

return false;
});
});
// ]]> </script>

21 comments:

  1. Works perfectly. Exactly what I was looking for. Thanks so much.

    ReplyDelete
  2. 1st hit on google, spot on!
    Cheers.

    ReplyDelete
  3. Hi nice code but i have an problem in IE.
    When i close the popup i get many scripterrors.
    Very often
    Line 48 character 12

    But just in IE

    And I was so happy found the code :(

    cheers
    Kruemel

    ReplyDelete
  4. Brilliant and correct in every way. Cheers!

    ReplyDelete
  5. Works perfectly, thank you mate :D

    ReplyDelete
  6. It works like a charm!
    I added a "'skin' : 'modieus.swf'" but dosent works. Any ideas? Thanks!

    ReplyDelete
  7. Solved!
    href="player.swf?file=video.mov&skin=modieus.swf&autostart=1"
    It works!

    ReplyDelete
  8. What if I want to use plugins? How would I load them using this method?

    ReplyDelete
  9. Oh never mind, I figured out I could serialize an object to be able to load the plugins I wanted:

    var params = {
    'width': '640',
    'height': '368',
    'file': 'sample/bitrates.xml',
    'plugins': {
    'qualitymonitor-2': {}
    'captions-2': {
    file: "sample/captions.xml"
    }
    }
    };

    $("#viewflv").attr("href", "js/player.swf?" + $.param(params));

    ReplyDelete
  10. Thx , working perfectly

    ReplyDelete
  11. Work great, if you don't need to support iPhones or iPads. The beautify of JWPlayer is it's ability to server non-Flash based video when needed. How do you integrate JWPlayer with Fancybox and maintain HTML5 support?

    ReplyDelete
    Replies
    1. If I remember the last time I tried, I ended up adding browser capability testing and going the HTML5 video route when it's supported, otherwise it fell back on JWPlayer.

      Delete
  12. Thank you so much for sharing this. You're great!

    ReplyDelete
  13. Big help, thanks!

    ReplyDelete
  14. great, but I have one problem in Google Chrome. when click on video it's not show like pop up, it redirect and play video in full screen. pls help!

    ReplyDelete
  15. Thanks man! works like my bitch....on fire!

    ReplyDelete
  16. Thanks very very much u helped me saving lots of times!!!

    ReplyDelete
  17. Thank you so much! It worked for me and I combined your idea with auto pop up Fancybox when a page is open. How can I share the whole code? it won't let me paste it :-s

    ReplyDelete
    Replies
    1. Hmm, try htmlencoding your code before pasting. For example, I pasted this:
      $(x).css("font-weight","bold");

      Delete
  18. So it would be like this:

    <!DOCTYPE html>
    <html>
    <script type="text/javascript" src="http://myhp.cri.hp.com/ticomunica/fancybox/lib/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="http://myhp.cri.hp.com/ticomunica/fancybox/source/jquery.fancybox.js"></script>
    <link rel="stylesheet" type="text/css" href="http://myhp.cri.hp.com/ticomunica/fancybox/source/jquery.fancybox.css" media="screen" />

    <script type="text/javascript">
    $(document).ready(function() {

    $("#yt").click(function() {
    $.fancybox({
    'padding' : 0,
    'autoScale' : false,
    'transitionIn' : 'none',
    'transitionOut' : 'none',
    'title' : this.title,
    'width' : 960,
    'height' : 720,
    'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
    'type' : 'swf',
    'swf' : {
    'wmode' : 'transparent',
    'allowfullscreen' : 'true'
    }
    });
    return false;
    });
    });
    $('#foo').bind('click', function() {
    alert($(this).text());
    });
    $('#foo').trigger('click');
    </script>
    <body onload='$("#yt").trigger("click");'>

    <p><a id="yt" title="" href="http://myhp.cri.hp.com/ticomunica/wp-content/plugins/flv-embed/flvplayer.swf?file=http://myhp.cri.hp.com/ticomunica/aniversario9.flv&amp;autostart=1"></a></p>
    </html>

    ReplyDelete