Extension:FlashMP3

FlashMP3 embeds a simple Flash-player for playback of mp3-files. It is based on the great Audio Player Wordpress plugin by 1pixelout. It can handle multiple local and/or remote files in one player and multiple players on each site. The appearance of the player is highly customizable.

It is also possible to use the nice last.fm player with the files hosted there. It works on an label, artist, album or song-level.

For problems and suggestions please use the discussion page of this article.

License
Copyright © 2007 Matthias Korn This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Base Syntax
filename.mp3 can be the name of a file uploaded to the Wiki or an external URL. Additional parameters are optional.

Multiple files
Multiple files can be played in one FlashMP3 player one after the other by separating them with comma.

Multiple players
Multiple FlashMP3 players on one site can be achieved by giving them an id.

secondmp3.mp3

Examples
mymp3.mp3

Plays an uploaded mp3-file called mymp3.mp3.

http://www.somedomain.com/mp3/mymp3.mp3

Plays the remote mp3-file from the URL http://www.somedomain.com/mp3/mymp3.mp3.

mymp3.mp3,yourmp3.mp3|autostart=yes|loop=yes

Plays the two uploaded files mymp3.mp3 and yourmp3.mp3 one after the other, autostarts playing when the site is loaded and loops the files.

Base Syntax
resourceID and resourceType have to be retrieved from the source of the last.fm page of which you want to embed the player (Right Click -> View Page Source and search for resourceID and resourceType). Both resourceID and resourceType are compulsory. Additional parameters are optional.

resourceType is either artist, album, song, label, playlist or the ID-number directly (if you know it).

Parameter Reference
Additional parameter are possible as long as the last.fm player can interpret them in the given situation (i.e. resourceType).

Examples
11572702|artist

Plays songs from the given artist (Tookoo).

51022335|song|firstTrackName=Dance+For+Yourself|firstArtistName=TOOKOO|albumArt=http://static.last.fm/coverart/130x130/3245162.jpg|restDuration=227

Plays the given song and displays the track name, artist name and duration as well as the cover right after loading.

Code
You can change the Default Title ($restTitle) and the Default Album Cover ($albumArt) in line 87 and line 91 respectively to your needs (for last.fm player only).

<?php

/*******************************************************************************
 * FlashMP3 Extension by Matthias Korn to embed a flash player with mp3-files  *
 * http://www.mediawiki.org/wiki/Extension:FlashMP3                            *
 * This extension uses the Audio Player Wordpress plugin from 1pixelout        *
 * Download and unpack files audio-player.js and player.swf to your            *
 * extensions/audio_player folder                                              *
 * http://www.1pixelout.net/code/audio-player-wordpress-plugin/              *
 * Tag :                                                                       *
 * mp3                                                  *
 * Example :                                                                   *
 * with a local file                                                         *
 * music.mp3                                            *
 * Example :                                                                   *
 * with a remote file                                                        *
 * http://www.somedomain.com/mp3/music.mp3              *
 * with a local file                                                         *
 * music.mp3                                            *
 * Example :                                                                   *
 * with a remote file                                                        *
 * http://www.somedomain.com/mp3/music.mp3              *
 * http://www.somedomain.com/mp3/music.mp3              *

$wgExtensionFunctions[] = 'wfFlashMP3'; $wgExtensionCredits['parserhook'][] = array(       'name' => 'FlashMP3',        'description' => 'Plays mp3-files in an embedded Flash-player',        'author' => 'Matthias Korn',        'url' => 'http://www.mediawiki.org/wiki/Extension:FlashMP3',        'version' => 'v0.91' );

function wfFlashMP3 { global $wgParser; $wgParser->setHook('flashmp3', 'renderFlashMP3'); }

// The callback function for converting the input text to HTML output function renderFlashMP3($input, $args) { global $wgScriptPath; $type = '1pixelout'; $id = 1; $params = explode("|", htmlspecialchars($input)); $files = explode(",", array_shift($params)); $player_path = $wgScriptPath.'/extensions/audio_player/'; if (isset($args['type'])) { $type = $args['type']; }       switch ($type) { case 'lastfm': // concat the parameter string $typeParameter = array_shift($params);	// this is the resourceType $param_string = implode('&amp;', $params); if (!empty($param_string)) {					$param_string = '&amp;'.$param_string; }				// try to figure out the resourceType $resourceTypes['artist']	= 6; $resourceTypes['album']	       =  8; $resourceTypes['song']		= 9; $resourceTypes['playlist']	= 10; $resourceTypes['label']		= 10;

if (is_numeric($typeParameter)) {					$resourceType = $typeParameter; } else { $resourceType = $resourceTypes[$typeParameter]; }				// the resourceID to play (either from an artist, song, playlist, ...) $resourceID = $files[0]; // setting default title and cover if (strpos($param_string, 'restTitle=') === false) {					$restTitle = '&amp;restTitle=Default Title';	// TODO: you can set a default title here }				if (strpos($param_string, 'albumArt=') === false) {					$albumArt = '&amp;albumArt=http://static.last.fm/depth/catalogue/noimage/cover_med.gif';	// TODO: you can set a default cover here }

$output .= '' . '' . '' . '' . '' . ' ';				break;

case '1pixelout': default: if (isset($args['id']) && preg_match('/^[a-z0-9]+$/iD', $args['id'])) { $id = $args['id']; }

// concat the file string for all files $file_string = ''; $j = 0; foreach ($files as $file) {					// get the intneral path if file is uploaded if (strpos($file, "http://") !== 0 && strpos($file, "https://") !== 0) {						$file = getFlashMP3Title($file);	// get Wiki internal url }					$file_string .= $file; if ($j < count($files)-1) $file_string .= ','; $j++; }				// concat the parameter string $param_string = implode('&amp;', $params); if (!empty($param_string)) $param_string .= '&amp;'; $output = ' ' . '' . '' . '' . '' . '' . '' . ' ';				break; }       return $output; }

function getFlashMP3Title($file) {   $title = Title::makeTitleSafe("Image",$file); $img = new Image($title); $path = $img->getViewURL(false); return $path; }

?>

Installation
1. Copy & Paste the code above in a file called flashmp3.php and place it in your extensions directory of your mediawiki folder.

2. Download the Audio Player plugin from 1pixelout. From the zip-archive copy the files audio-player.js and player.swf in a new folder called audio_player in your extensions directory.

3. Put this line near the end of your LocalSettings.php in the mediawiki root-folder to include the extension. include('extensions/flashmp3.php');

Uploading mp3-files
To be able to upload mp3-files to your mediawiki also do the following steps.

4. Allow uploading of mp3-files by adding this line near the end of your LocalSettings.php. $wgFileExtensions[] = 'mp3';

5. Set the maximum size for file uploads in your php.ini.

6. Set the maximum size for file uploads by adding this line to your LocalSettings.php. $wgMaxUploadSize = '50MB';

Limitations

 * The default player has a white background at the beginning when still folded. This is a limitation of the 1pixelout player and can not be changed. (Firefox on Linux only!?)
 * For the last.fm player you have to search the source code to find the resourceID. To my knowledge there is no better way to do this at the moment.

Changelog

 * v0.91 (2007-04-03)
 * fixed some possible Cross-site scripting vulnerabilities


 * v0.9 (2007-03-04)
 * added last.fm player


 * v0.8 (2007-02-25)
 * initial release