A Django template tag for integrating a Flash based flv player

This blog entry was posted by peter on September 28, 2007.

It is tagged with Django, Flash, flv, template, and video.

So far there are 2 comments. Feel free to add one.

The previous entry chronologically is Experiments on Last.FM in X3D.

A Django application for integrating a Flash based videoplayer into templates using a custom template tag. It is based on the videoplayer from JW FLV Player and can be easily customized by template parameters.

License

The Django application code is licensed under a BSD license.

The application uses the JW FLV Player by Jeroen Wijering which is licensed under a Creative Commons License.

Download

The flvplayer app is only available as a tarball. It contains the Django application and the flashplayer from JW FLV Player.

Installation

To install the videoplayer app, follow these steps:

  1. Unpack the downloaded tarball in your projects directory
  2. Add myproject.flvplayer“ to your INSTALLED_APPS variable
  3. Configure your webserver or urls.py to serve the Flash file player.swf found in the media/flvplayer subdirectory. By default the player is searched at {{ MEDIA_URL }}/flvplayer/flvplayer.swf but that can be changed (see below).

That’s it. The flvplayer does not use any models or views, only a custom template tag named flvplayer.

Using the flvplayer template tag

The flvplayer can be used in any template like this:

1
2
3
4
{% load flvplayer %}
# …
{% flvplayer file=file_url %}
# …

First load the flvplayer template tag library, then instantiate the player as often as you like, using different files and/or player configurations.

Here’s a live example: 

Customizing the flvplayer

The flvplayer can be customized to fit your project’s needs.You can set looping, width, height and the colors for the various player areas like this:

1
{% flvplayer file=file_url,autostart=True,backcolor=0xff000 %}

The following table contains the full list of supported parameters. The original can be found at jeroenwijering. Please be aware that the original values for bool variables have been pythonified: Instead of using true and false the flvplayer tag can also use False and True.

Please refer to jeroenwijering for a detailed explanation of the parameters. Note that not all parameters are supported by the template tag right now.

ParameterDefaultDescription
file
    The URL of the flv file
    playerUrlsee belowThe URL of the player.swf file
    image
      Preview image (JPG/SWF/PNG/GIF)
      displayheight
        Height of the display
        displaywidth
          Width of the display
          height
            Height of the player
            width
              Width of the player
              backcolor0xFFFFFFBackground color of the player
              frontcolorTexts / buttons color of the player
              lightcolorRollover/ active color of the player
              autostartFalseSpecifies whether the player starts automatically. Can be one of [True,False,Muted]
              autoscrollFalsePlaylist scrollbar behaviour
              largecontrolsFalseMake the controlbar twice as large
              logo
                Logo in the top right corner of the display
                overstretch
                  How to stretch movies to make them fit the display
                  showdigitsTrue
                  showvolumeTrueShow/hide the volume button
                  bufferlength3Number of seconds an FLV should be buffered ahead
                  repeatFalse
                  volume80

                  Serving the Flash player

                  By default the flvplayer tag uses the flvplayer.swf found at {{ MEDIA_URL }}/flvplayer/flvplayer.swf.

                  To change that behaviour pass the URL of the player using the playerUrl parameter like this:

                  1
                  {% flvplayer file=file.mp3,playerUrl=/foo/bar/player.swf %}
                  

                  Inserted code

                  The following code is inserted by the flvplayer template tag based on the flvplayer/flvplayer.html template (the shown code is just an example and varies depending on your parameters):

                  1
                  2
                  3
                  4
                  5
                  6
                  7
                  8
                  <object classid=“clsid:d27cdb6e-ae6d-11cf-96b8-444553540000” codebase=“http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0” width=“180” height=“60”>
                      <param name=“width” value=“180” />
                      <param name=“height” value=“60” />
                      <param name=“bgcolor” value=“f2f2f2” />
                      <param name=“flashvars” value=“height=18&amp;amp;bg=0xF7F7F7&amp;amp;slider=0xB29461&amp;amp;track=0xFFFFFF&amp;amp;righticon=0x666666&amp;amp;lefticon=0x666666&amp;amp;soundFile=%2Fmedia%2Faudio%2FSuitcase_-_Sheep.mp3&amp;amp;loader=0xEEFFCC&amp;amp;rightbg=0x22C1D6&amp;amp;bgcolor=0xf2f2f2&amp;amp;rightbghover=0x32D1E6&amp;amp;autostart=no&amp;amp;text=0x4F4F4F&amp;amp;leftbg=0xBAFF7B&amp;amp;righticonhover=0x444444&amp;amp;border=0x00FF00&amp;amp;width=156&amp;amp;loop=no” />
                      <param name=“src” value=“/media/flvplayer/flvplayer.swf” />
                      <embed type=“application/x-shockwave-flash” width=“180” height=“60” bgcolor=“f2f2f2” flashvars=“height=18&amp;amp;bg=0xF7F7F7&amp;amp;slider=0xB29461&amp;amp;track=0xFFFFFF&amp;amp;righticon=0x666666&amp;amp;lefticon=0x666666&amp;amp;soundFile=%2Fmedia%2Faudio%2FSuitcase_-_Sheep.mp3&amp;amp;loader=0xEEFFCC&amp;amp;rightbg=0x22C1D6&amp;amp;bgcolor=0xf2f2f2&amp;amp;rightbghover=0x32D1E6&amp;amp;autostart=no&amp;amp;text=0x4F4F4F&amp;amp;leftbg=0xBAFF7B&amp;amp;righticonhover=0x444444&amp;amp;border=0x00FF00&amp;amp;width=156&amp;amp;loop=no” src=“/media/cms/flvplayer/player.swf”></embed>
                  </object>
                  

                  Replacing the default code template

                  The code shown above is read from the template flvplayer/flvplayer.html. You can provide a custom template to adopt the code to your needs. The template will be passed the following context variables:

                  player_url
                  The URL of the flv player.
                  width
                  The width of the player.
                  height
                  The height of the player.
                  flash_vars
                  The flashvars for the player.

                  Alternatives

                  JavaScript

                  Instead of integrating the flvplayer using a template tag one could also use some JavaScript to add the player to the page.


                  Comments

                  bernd said on October 05, 2007

                  look cool, I test it soon.
                  Thanks for that.

                  fladd said on March 03, 2008

                  Hi there,

                  just trying this, very cool. But, why isn't it showing thumbnails in the playlist?

                  Add a comment