Community & Support

Question for Audio module developers: Adding another Flash player

Hello. Sorry if this is in the wrong forum, but I couldn't find a better one really.

I'm using the Audio module, and I'd like to install another Flash player for my site. FYI, it has the rather unimaginable name of Flash MP3 Player, and it's here:
http://flash-mp3-player.net/

Reason being that I'm already using it, and know how to skin it and so forth.

My question: How do I alter the Audio module to use it?

I've read this tutorial about writing a theme override:
http://drupal.org/node/134523

...but it's an old tutorial, applying only to D4.7, so I doubt it would work now.

I looked through the code in audio.module, and it LOOKS like I would only need to include these things in the /players directory:
- the PLAYERNAME.swf file
- a same-named PLAYERNAME.inc file with an $items['PLAYERNAME'] array, and a theme_audio_PLAYERNAME_node_player() function
- (optionally?) a preview .png, and the license (which is either CC-BY-SA or MPL1.1)

(Also an XML file, but that's because Flash MP3 Player needs it for the skin.)

That's if I understand the code in function _audio_player_build_list() correctly:

function _audio_player_build_list() {
  // Invoke any modules that implement the hook.
  $players_name = module_invoke_all('audio_player');

  // Load all our module's player plugins.
  $path = drupal_get_path('module', 'audio') .'/players';
  $files = drupal_system_listing('.inc$', $path, 'name', 0);
  foreach ($files as $file) {
    require_once('./'. $file->filename);
    $function = 'audio_'. $file->name .'_audio_player';
    if (function_exists($function)) {
      $result = $function();
      if (isset($result) && is_array($result)) {
        $players_name = array_merge($players_name, $result);
      }
    }
  }

  // Group players by format.
  $players_format = array();
  foreach ($players_name as $name => $player) {
    foreach ($player['formats'] as $format) {
      $players_format[$format][$name] = $player;
    }
  }

  return array($players_name, $players_format);
}

This seems to just be scanning the players/ directory, and including/parsing all the .inc files there.

Is this correct?

If it is, then you should probably make this fact available somewhere. Most of the Audio docs seem a bit outdated. Creating a new .inc file and dumping a Flash file in players/ is pretty simple, so just about anyone could include a patch for almost every player...

Comments

Success!

My, how quickly posts drop off the front page...

I didn't get an answer, so I tried it myself, and - success!

For those who want to do this themselves, here's a template for YOURPLAYER.inc:

<?php

function audio_YOURPLAYER_audio_player() {
  $items['YOURPLAYER'] = array(
    'module'      => 'audio',
    'title'       => t('YOURPLAYER Flash player'),
    'description' => t('YOURPLAYER description'),
    'url'         => t('http://www.YOURPLAYER.com/'),
    'preview'     => 'players/YOURPLAYER.png',
    'formats'     => array('wav', 'mp3'),
    'theme_node'  => 'audio_YOURPLAYER_node_player',
  );
  return $items;
}

function theme_audio_YOURPLAYER_node_player($node, $options = array()) {
  // make sure it's compatible with the flash player
  if (!audio_is_flash_playable($node)) {
    return NULL;
  }

  $options['soundFile'] = check_url($node->url_play);
  $url = base_path() . drupal_get_path('module', 'audio') .'/players/YOURPLAYER.swf';
  $flashvars = audio_query_string_encode($options);

$output = <<<EOT
<object type="application/x-shockwave-flash" data="$url" width="290" height="24" >
  <param name="movie" value="$url" />
  <param name="wmode" value="transparent" />
  <param name="menu" value="false" />
  <param name="quality" value="high" />
  <param name="FlashVars" value="$flashvars" />
  <embed src="$url" flashvars="$flashvars" width="290" height="24" wmode="transparent" />
</object>
EOT;

  return $output;
}

Notes:
1. Substitute YOURPLAYER with your player's file name.

2. Instead of this line:
$url = base_path() . drupal_get_path('module', 'audio') .'/players/YOURPLAYER.swf';
...I think you could substitute another path to the SWF file (if, for instance, you have SWF Tools installed and want this to point to FlowPlayer). Same goes for $items['YOURPLAYER']['preview']. (I actually haven't tried this to confirm but it SHOULD work...)

3. You can put in other formats into $items['YOURPLAYER']['formats'] if your Flash player can handle other formats. This makes the Audio module good for e.g. video files. You would of course have to enable those formats in Administer > Site Configuration > Audio Settings.

4. The tutorial I linked to earlier does, indeed, work. I personally skinned the 1pixelout player using this tutorial:
http://www.innovatingtomorrow.net/2007/10/22/how-theme-1pixelout-flash-p...
...but if your flash player is skinnable by passing options to the Flash object, then it should work for your player as well.

Happy coding!

-Karlheinz