The SWF Tools input filter is included as part of the core SWF Tools module, so when you enable SWF Tools the filter is available. The input filter lets you generate flash content and access the various media player modules by using a simple syntax of the form [swf file="myFlash.swf"] for a single file, or [swf files="Music1.mp3&&Music2.mp3&&...] for a list of files.

To use the input filter you must first assign it to some input formats where it will be allowed to be used. To do this:

  1. go to Site configuration > Input formats
  2. choose Configure to add the filter to an existing input type, or choose Add input format to create a new format.
  3. Place a check next to the SWF Tools filter and then save the configuration.

By default the SWF Tools filter is given a weight of 10 which means it will be one of the last filters to run, and generally this is the best option. If you need to re-arrange the filters then use the Re-arrange option on the input filters configuration page.

The SWF Tools filter will need to come after any HTML corrector modules, or modules that strip tags. If the SWF Tools filter comes before these then there is a risk that the flash won't display. It can take some trial and error, but it is designed to work first time, as far as can ever be the case!

If you find you get some of the SWF Tools embedding content actually displaying on the page then double check the filter settings. If you have several filters with the same weight as SWF Tools then try weighting SWF Tools more heavily, or lighten the others.

Once the filter has been activated you can start adding flash content to pages by using the [swf] format.

To add a single file simply write [swf file="myFile.swf"]. Note - this will refer to a file in the default file directory of your site. If you want to refer to elsewhere then you can refer to sub-directories by using [swf file="subdirectory/anotherFile.swf"]. If you want to refer to external files, or somewhere outside of the Drupal file system, then use a full path, such as [swf file="http://example.com/externalFile.swf"].

When you supply a filename to the SWF Tools filter then it will try to work out what to do with the file based on its extension. So swf files just get displayed, mp3 files are passed to the default mp3 player, and a list of flv's would go to the configured flv player.

To override the width and/or height, you can add them inside the brackets, such as [swf file="myFile.swf" width="400" height="250"].

To refer to a list of files replace [swf file="oneFile.swf"] with [swf files="Music1.mp3&&Music2.mp3&&..."]. Note that in the list of files double ampersands are used to separate each file! Behind the scenes SWF Tools will convert the list of files in to an appropriate format for the media player that is going to be used.

If you have used an earlier version of SWF Tools then existing nodes that use the format [swflist files="..."] will still work. However, it is no longer necessary to use the [swflist] syntax, unless you are using the Drupal 5 version, since just passing either file or files is enough to tell SWF Tools what to do.

Over-riding the embedding method

If necessary the default embedding method can be over-ridden by passing the parameter embed="{method}" in the filter, where {method} is the method name you want to use. The method name is an internal name that SWF Tools uses to identify available methods.

Method Method name
Direct embedding swftools_nojavascript
SWF Object 2 swfobject2_replace
SWF Object 1.5 swfobject_replace
jQUery Flash lutman_replace
UFO ufo_replace

Forcing a specific media player

Sometimes you may want to force SWF Tools to use a specific player to play back a media item. This might occur if you want to use a player other than the default, or if the auto-detection of the media type is failing.

To force a specific player use the parameter player="{player}" in the filter, where {player} is the player name you want to use. The player name is an internal name that SWF Tools uses to identify available players.

Player Player name
FlowPlayer flowplayer_mediaplayer
FlowPlayer 3 swftools_flowplayer3_mediaplayer
JW Image Rotator 3 wijering_imagerotator
JW Media Player 3 wijering_mediaplayer
JW Media Player 4 wijering4_mediaplayer
Simple Viewer simpleviewer
1 Pixel Out Player onepixelout

Forcing a specific action

Sometimes you may want to force SWF Tools to use a specific action to play back a media item. This might occur if the auto-detection of the media type is failing so the wrong action is being assigned.

To force a specific action use the parameter action="{action}" in the filter, where {action} is the action name you want to use. The action name is an internal name that SWF Tools uses to identify available actions.

Action Action name
Display as an swf (no player) swftools_swf_display_direct
Play a single mp3 swftools_mp3_display
Play a list of mp3s swftools_mp3_display_list
Play a single flv swftools_flv_display
Play a list of flvs swftools_flv_display_list
Play a list of images swftools_image_display_list
Play a list of mixed media swftools_media_display_list

Specifying flashvars

If you want to send a string of flash variables to the movie then you can include this in the input filter by writing [swf file="myMovie.swf" flashvars="var1=Something&&var2=SomethingElse"]

Note that you have to use a double ampersand, and that you cannot include an unescaped quote in the flashvars string as this will confuse the filter!

Comments

James Marks’s picture

It's possible, although not immediately obvious, to set other parameters for the video player such as height and width using the swf input filter like:
[swf file="flash_video_file.flv" params="width=400&&height=300"]

aliciatheduff’s picture

Also helpful, if you've put your swf and xml in a subdirectory and it's not finding the xml try setting the base url to match:
[swf file="subdirectory/movie.swf" params="base=http://www.website.com/sites/default/files/subdirectory/"]

kiwiviktor81’s picture

I tried params="width=50%&&height=50%" but that doesn't work. Any ideas?

treehacker’s picture

Just use: [swf file="file.swf" width="950" height="480"]
;-)

andraaspar’s picture

It would be worth to mention that you can force a flash version that is different from the default, by using:

[swf file="flash/myflash.swf" params="version=10.0.22"]

martysteer’s picture

This square bracket replacement is my preferred option. I tried the hack below for the last month and TinyMCE leaves mce_bogus and mce_href attributes throughout all my other edited pages.

koppie’s picture

Even though I checked all the right options, TinyMCE was still scrubbing out my calls. Even though this has been discussed elsewhere, I couldn't find any newbie instructions for the new Drupal 6 WYSIWYG module with TinyMCE, so here you go:

(1) Edit /sites/all/modules/wysiwyg/editors/tinymce.inc
(2) Find "function wysiwyg_tinymce_settings($editor, $config, $theme) {" and add "'cleanup' => FALSE," to the end of it, so it looks like this:

function wysiwyg_tinymce_settings($editor, $config, $theme) {
  $init = array(
    'button_tile_map' => TRUE, // @todo Add a setting for this.
    'document_base_url' => base_path(),
    'mode' => 'none',
    'plugins' => array(),
    'theme' => $theme,
    'width' => '100%',
    // Strict loading mode must be enabled; otherwise TinyMCE would use
    // document.write() in IE and Chrome.
    'strict_loading_mode' => TRUE,
    // TinyMCE's URL conversion magic breaks Drupal modules that use a special
    // syntax for paths. This makes 'relative_urls' obsolete.
    'convert_urls' => FALSE,
    'cleanup' => FALSE,
  );

Note: by doing this, you've completely turned off TinyMCE's scrubbing feature. This is not recommended by people who know better.

greg.harvey’s picture

And kittens will die, you hacker you!

Surely there's a GUI option to turn off clean-up?

adVid’s picture

Thank you koppie, it works. It's dirty but it works :(

Is it the same with other editors ?

Sabino’s picture

I just cannot figure out how to use my favored onepixelout-player. After installing swftools the generic player does work.
There is a directory modules/swftools/onepixelout. I uploaded the stand-alone onepixelout-player to this directory. When I browse to "admin/settings/swftools/handling" I get the message "Missing 1pixelout/player.swf". I tried some variations about placing the files in different sub-directories and naming them 1pixelout and onepixelout but swftools still won't find the player. Is there any help for this problem?

Stuart Greenfield’s picture

This documentation has a table that gives the path and name needed for each player.

pintuindia’s picture

download the onepixelout http://downloads.wordpress.org/plugin/audio-player.1.2.3.zip

extract the file and rename it to 1pixelout and put it into the sites/all/module/swftools/shared/

Sabino’s picture

Thanks.
1pixelout does work now.

adVid’s picture

In config, I unset checking files and I'm using public file system.

If I write [swf file="test.swf"] then movie parameter is set to "http://www.domain.com/sites/default/files/".
Same behaviour if I write [swf file="/path/test.swf"] or [swf file="/sites/default/files/path/test.swf"].
"file" value is always omitted unless I set full path access to "test.swf".

What did I miss ??

Thank you.

Firetracker’s picture

Hi,

I've got the same problem. Did you sort it?

Cheers
Zap

adVid’s picture

No. And it seems that nobody care about this :(

alexharries’s picture

I've just come across this gotcha too - it's a bit of a usability problem, as your users will probably upload the FLV via the upload module and simply want to copy the path - minus your domain name if they're clever enough to use relative links - into the [swf file="/path/to/file.flv"] string.

The two solutions here are either to improve documentation so editors only insert filenames/paths relative to the Drupal files directory root, without a leading '/', or modifying the file to be better able to handle paths relative to the wwwroot.

I've cobbled together a patch file against 6.x-2.5 which does a few things to try and improve reliability, below, but I'm no coder, so it probably needs rewriting, but it has allowed me to specify the file URL as the path from the server root, i.e. with a leading slash: [swf file="/sites/www.kssdeanery.org/files/noodle.flv"].

At the moment, a correct path begins in your files directory, but you CANNOT have a leading slash, so you can't use / to "reset" your URL. e.g. "/foo/bar.flv" won't reset the URL to your base_url.

Anyway, here's how I think you can find out your path - go to:
admin/settings/swftools/handling

... and scroll down to "Media directory url". On my system, I see something like "http://www.example.com/sites/www.example.com/files" - note the lack of trailing slash; what you put in file="filename" is probably simply appended to this path.

Why is this bad? Two reasons I guess; the first is as mentioned above - generally, you want your users to think in terms of relative, portable and recognisable paths. I know that example.com/foo/bar/baz will work anywhere on example.com, and it's easy to make it work from another domain too simply by adding example.com to the start.

The second issue is that this problem is maybe caused by the assumption that Drupal users are comfortable with all their uploads being served from the site's files directory; this isn't always the case, and it's probably better for user interface standards to simply give the user the full path to the media - including the http://, etc (like upload module does on node/edit pages) and let them decide what to do with it.

Lastly, the error message "" should include the path the SWF Tools filter is resolving from the user's input in [swf file="/foo..."], and the directory it is using as a base dir. Even better, have it also explain using an example.

--- swftools.module	2009-12-04 05:06:46.781165283 +0000
+++ swftools_20091204_filepath_fix.module	2009-12-04 05:10:32.997979037 +0000
@@ -424,7 +424,6 @@ function swf($file, $options = array()) 
     $nocache = '';
   }
 
-  
   // FILE
   // Make sure that the file path is $file is valid - we skip this section if $file is already a full url
   // Otherwise we try to expand it to a full url to the local file system or the remote media directory
@@ -434,7 +433,6 @@ function swf($file, $options = array()) 
     
   // If $file isn't a valid url, and if the file isn't going to be streamed, then try to work out where it is
   if (!valid_url($file, TRUE) && !isset($vars->othervars['stream'])) {
-    
     // If we don't have a playlist...
     if (empty($playlist)) {
       
@@ -442,12 +440,15 @@ function swf($file, $options = array()) 
       
       // Then check if files are being sourced locally, and if they are build a file path
       if (swftools_get_media_path()) {
-        $file = file_create_path($file);
+        // Fail: file_create_path is both destructive and obscure: if it doesn't like the user's input,
+        // it will empty it.
+        //$file = file_create_path($file);
+        $file_url = swftools_validate_file_url($file);
       }
     }
 
     // Try to turn $file in to a complete url, either local or remote
-    $file_url = swftools_get_media_url($file);
+    $file_url = ($file_url ? $file_url : swftools_get_media_url($file));
 
     // If $file_url was not generated then file doesn't exist so return $html_alt
     if (!$file_url) {
@@ -529,6 +530,81 @@ function swf($file, $options = array()) 
   return theme('swftools_embed', $embed_markup, $action, $resolved_methods, $vars, $html_alt);
 }
 
+function swftools_validate_file_path($file) {
+  //wrapper function for swftools_validate_file_url($file,TRUE)
+  return swftools_validate_file_url($file,TRUE);
+}
+
+function swftools_validate_file_url($file,$return_path = FALSE) {
+  // Parameters:
+  //  $file         A filename relative to the Drupal files dir (no leading '/'), site
+  //                dir (no leading '/'), or wwwroot (including the leading '/').
+  //  $return_path  Whether to return the absolute path to the file (if TRUE), or just
+  //                a relative URL (i.e. one which will work in an <a href="$file"> anchor,
+  //                e.g. '/sites/www.example.com/files/foo_bar.flv'
+  // Function attempts to work out a file's absolute path on the server, given
+  // either a filename relative to the Drupal files directory, or a filename
+  // relative to the Drupal install. If a file exists at these paths, return
+  // the web-accessible path; otherwise, return FALSE. Function designed to replace
+  // the file_create_path call in swf() @447-ish which was eating web-safe, perfectly
+  // acceptable filenames.
+  //
+  /* Examples:
+      
+      Drupal at wwwroot:
+        $file:    /sites/www.example.com/files/foo_bar.flv
+        Site:     www.example.com/ 
+        Files:    sites/www.example.com/files
+        Call:     swftools_get_file_web_path('/sites/www.example.com/files/foo_bar.flv')
+        Return:   http://www.example.com/sites/www.example.com/files/foo_bar.flv if the file exists
+        
+        $file:    sites/www.example.com/files/foo_bar.flv
+        Site:     www.example.com/
+        Files:    sites/www.example.com/files
+        Call:     swftools_get_file_web_path('sites/www.example.com/files/foo_bar.flv')
+        Return:   http://www.example.com/sites/www.example.com/files/foo_bar.flv if the file exists
+        
+        $file:    foo_bar.flv
+        Site:     www.example.com/
+        Files:    sites/www.example.com/files
+        Call:     swftools_get_file_web_path('foo_bar.flv')
+        Return:   http://www.example.com/sites/www.example.com/files/foo_bar.flv if the file exists
+        
+      Subdir Drupal:
+        $file:    /drupal/sites/www.example.com/files/foo_bar.flv
+        Site:     www.example.com/drupal/ (i.e. Drupal in a subdir)
+        Files:    sites/www.example.com/files
+        Call:     swftools_get_file_web_path('/drupal/sites/www.example.com/files/foo_bar.flv')
+        Return:   http://www.example.com/drupal/sites/www.example.com/files/foo_bar.flv if the file exists
+        
+        $file:    sites/www.example.com/files/foo_bar.flv
+        Site:     www.example.com/drupal/ (i.e. Drupal in a subdir)
+        Files:    sites/www.example.com/files
+        Call:     swftools_get_file_web_path('sites/www.example.com/files/foo_bar.flv')
+        Return:   http://www.example.com/drupal/sites/www.example.com/files/foo_bar.flv if the file exists
+        
+        $file:    foo_bar.flv
+        Site:     www.example.com/drupal/ (i.e. Drupal in a subdir)
+        Files:    sites/www.example.com/files
+        Call:     swftools_get_file_web_path('foo_bar.flv')
+        Return:   http://www.example.com/drupal/sites/www.example.com/files/foo_bar.flv if the file exists
+        
+  */
+  $file = (substr($file,0,1) == '/' ? substr($file,1) : $file);
+  
+  // Set our prefix - either http://www.example.com/install_directory/ or /path/to/install/root/
+  // Note the trailing slash! :)
+  $prefix = ($return_path ? realpath('.') . '/' : url('<front>',array('absolute' => TRUE)));
+  
+  // Attempt to get the file's complete URL - rudimentary check. Will undoubtedly
+  // need beefing up to handle a wider range of possibilities, but this check should
+  // always remain as simple as possible to debug.
+  $file_absolute = ($file_absolute ? $file_absolute : (file_exists(realpath('.') . '/' . $file) ? $prefix . $file : NULL));
+  $file_absolute = ($file_absolute ? $file_absolute : (file_exists(realpath('.') . '/' . swftools_get_media_path() . '/' . $file) ? $prefix . swftools_get_media_path() . '/' . $file : NULL));
+  
+  // Done. If we have $file_absolute, return it, else return FALSE
+  return ($file_absolute ? $file_absolute : FALSE);
+}
 
 /**
  * Produce finished markup ready for inserting on the page
@@ -806,8 +882,17 @@ function swftools_get_media_url($path, $
   if (variable_get('swftools_check_media', TRUE) && $is_file) {
     
     // If the file doesn't exist, set an error message and return FALSE to indicate failure
-    if (!file_exists($path)) {
-      drupal_set_message(t('Could not display the flash because %path does not appear to exist.', array('%path' => $path)), 'error');
+    //if (!file_exists($path)) {
+    // More file-based-fail, above: $path will almost never resolve to a local filename.
+    // Instead, work out the absolute path instead.
+    if (!file_exists(swftools_validate_file_path($path))) {
+      // Ahh feck it, the file can't be found. Set a warning (not an error - it's
+      // not the end of the world, as the site won't automagically catch fire) and
+      // get on with one's life...
+      drupal_set_message(t('SWF Tools could not display the media content because
+        the file at "%path" could not be located. Please re-check the file path,
+        or see ' . l('drupal.org/node/12345','http://drupal.org/node/12345') . '
+        for more information on embedding media using SWF Tools.', array('%path' => $path)), 'warning');
       return FALSE;
     }
   }
matthiasvanneste’s picture

I cannot seem to get this to work. I've set up SWF Tools to use SWFObject2 embedding, according to the swttools status report all ok. But when I add any of these snippets to a page it does not get replaced. I just get the code snippet in text on the page.

Any advice on what I'm doing wrong here ?

Many Thanks !

alexharries’s picture

Just to check, have you enabled the [swf ...] insert filter in admin/build/modules, and ticked to enable the insert filter in your input format(s) via admin/settings/filters?

Anonymous’s picture

I have these enabled. I can use [swf file="sac1.flv"] but if I make a playlist [swf file="sac1.flv&&sac1.flv"] it errors out.

Could not display the flash because sites/default/files/sac1.flv&amp;&amp;sac2.flv does not appear to exist.

cesar.brod@gmail.com’s picture

Did you make it work?

ZoeN’s picture

Can I put in a parameter that will make it output a download link as well as the player? And also, is there a full list somewhere of all the parameters that can be passed?

Zoe Neill-St. Clair
Drupalshank @ Affinity Bridge
http://www.AffinityBridge.com

sainzu’s picture

Sounds like you want to put in alternate text/html that will display if flash fails to load... Have you found a solution to this problem using this input filter? I'd love to know. I know you can inject alternate html using the swf() php function call. But I don't want to use php input filter just for this purpose as it is a security issue. Does anyone know if there is a parameter that lets you insert alt text using this input filter? Should this be a feature request?

cientista’s picture

Hi,

I have successfully set up RTMP streaming on flv files from a CDN. Also I have discovered that I can get Flowplayer 3 to play mp4 files by direct linking to the CDN but not with rtmp://, instead http://. This is financially a problem as each time the whole file is being downloaded. The problem comes about as SWF tools syntax defines 'swftools_flv_display' ok for flv... but what about 'swftools_mp4_display' this does not exist...!? So how do we get FLV tools to display the mp4 from a remote server??

Does this require PHP? If so I'm out of it! This issue is important as it is possible to get FAR superior compression with h.264/mpeg-4 as opposed to blocky flash.

Cheers,
Andy

wolfie71’s picture

Is it possible, and if yes how, can I send variables from url to inside a flash swf. Something like this:

flash.swf?vars1=topo1|topo2|topo3&vars2=A

Thanks
Edu

oswaldo.otero’s picture

I created a Content Type for video and I created a filefield to upload and flv file. Is there anyway to make it play as an external url like a third party source?

Thanks

Steel Rat’s picture

I'm trying to create a splash page for a D6 site, using the Front Page module, and SWFtools. I need to display a flash video on the splash page, but nothing I'm trying even recognizes the video file. I've tried without SWFtools, using standard object embedding options, but neither the video nor a placeholder even appear. With swftools all I see is the [swf file="splashvideo.flv"] label and nothing else.

Any ideas?

Thanks!

lordrt21’s picture

Did you install flowplayer, as I play all my flvs with this player using swftools

lordrt21’s picture

How can I make my flv loop continuously using the filter?

Anonymous’s picture

Hi there,
am new to SWF Tools and I want to work with JW Media Player 4 using the SWF Input Filter. I've videos with different sizes and each video has an individual preview picture. Finally I want to use this player for mp3 too. My questions:

• How can I define a preview picture using the SWF Input Filter [swf file="…"]?
• How can I define a size using the SWF Input Filter?
• Is it possible to display mp4 videos with SWF Tools and JW Media Player 4?

I know JW Media Player and in HTML projects I've defined individual players for each video to have individual preview pictures, sizes and contents. I've installed SWF Tools and JW Media Player 4 and it works but without special features I mentioned above. Would be glad if anybody could help and tell me some strings I've to write into the SWF Input Filter [swf file="…"].

Thanks

treehacker’s picture

Just use: [swf file="file.swf" width="950" height="480"]

_vid’s picture

To add custom alternative content with the input filter, include html_alt="" in your code.
Examples:

[swf html_alt="<img src='/sites/default/files/my_image.jpg' alt='Replacement image used when flash does not load'/> You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialize correctly. <br />Direct link: my/streaming/video/server/my_video.mp4" files="my/streaming/video/server/my_video.mp4"]

To load a movie with a set width and height with custom options: wijering4_mediaplayer, width, height, autoPlay and html_alt:

[swf flashvars="width=640&&height=480&&autoPlay=false" loop="false" player="wijering4_mediaplayer" html_alt="<img src='/sites/default/files/my_image.jpg' alt='Replacement image used when flash does not load'/> You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialize correctly. <br />Direct link: my/streaming/video/server/my_video.mp4" files="my/streaming/video/server/my_video.mp4"]