Difference between revisions of "Help:FlashMP3"

From My Big TOE Wiki
Jump to: navigation, search
(Created page with "{{extension |name = FlashMP3 |status = beta |type = tag |author = Matthias Korn |image = |version = v0.92 |update = 2012-01-20 |mediawiki = |download = ...")
Line 170: Line 170:
Plays the given song and displays the track name, artist name and duration as well as the cover right after loading.
Plays the given song and displays the track name, artist name and duration as well as the cover right after loading.
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).
<source lang="php">
if ( ! defined( 'MEDIAWIKI' ) )
*                                                                              *
* 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/FlashMP3 folder                                                  *
*                                                                              *
*  http://www.1pixelout.net/code/audio-player-wordpress-plugin/              *
*                                                                              *
* Tag :                                                                        *
*  <flashmp3>mp3</flashmp3>                                                  *
*                                                                              *
* Example :                                                                    *
*  with a local file                                                          *
*  <flashmp3>music.mp3</flashmp3>                                            *
*                                                                              *
* Example :                                                                    *
*  with a remote file                                                        *
*  <flashmp3>http://www.somedomain.com/mp3/music.mp3</flashmp3>              *
*                                                                              *
$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.92'
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/FlashMP3/';
        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 .= '<object width="340" height="123">'
. '<param name="movie" value="http://static.last.fm/webclient/41/defaultEmbedPlayer.swf" />'
. '<param name="FlashVars" value="viral=true&amp;lfmMode=playlist&amp;resourceID='.$resourceID.'&amp;resourceType='.$resourceType.$albumArt.$restTitle.$param_string.'" />'
. '<param name="wmode" value="transparent" />'
. '<embed src="http://static.last.fm/webclient/41/defaultEmbedPlayer.swf" width="340" '
. '  FlashVars="viral=true&amp;lfmMode=playlist&amp;resourceID='.$resourceID.'&amp;resourceType='.$resourceType.$albumArt.$restTitle.$param_string.'"'
. '  height="123" wmode="transparent" type="application/x-shockwave-flash" />'
. '</object>';
case '1pixelout':
        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 intenral path if file is uploaded
        if (strpos($file, "http://") !== 0 && strpos($file, "https://") !== 0) {
    $title = Title::newFromText($file,NS_IMAGE);
    if($title == NULL){
return FlashMP3NotFoundError($file);
    $img = function_exists( 'wfFindFile' ) ? wfFindFile( $title ) : new Image( $title );
    if ( $img ) {
$file = $img->getURL();
    } else {
return flashMP3NotFoundError($file);
$file_string .= $file;
if ($j < count($files)-1) $file_string .= ',';
// concat the parameter string
$param_string = implode('&amp;', $params);
if (!empty($param_string)) $param_string .= '&amp;';
$output = '<script language="JavaScript" src="'.$player_path.'audio-player.js"></script>'
. '<object type="application/x-shockwave-flash" data="'.$player_path.'player.swf" id="audioplayer'.$id.'" height="24" width="290">'
. '<param name="movie" value="'.$player_path.'player.swf">'
. '<param name="FlashVars" value="playerID='.$id.'&amp;'.$param_string.'soundFile='.$file_string.'">'
. '<param name="quality" value="high">'
. '<param name="menu" value="false">'
. '<param name="wmode" value="transparent">'
. '</object>';
        return $output;
function flashMP3NotFoundError($input) {
    return '<div style=\'border: solid red 1px\'>
<p align=center><b>Error: file <code>'.$input.'</code> not found </b> </p><br>
1. Copy & paste the code above in a file called '''flashmp3.php''' and place it in a new folder called ''FlashMP3'' in your extensions directory.
2. Download the standalone Audio Player plugin from [http://wpaudioplayer.com/download 1pixelout]. From the zip-archive copy the files '''audio-player.js''' and '''player.swf''' in the folder ''FlashMP3''.
3. Put this line near the end of your LocalSettings.php in the MediaWiki root folder to include the extension.
<source lang="php">require_once('extensions/FlashMP3/flashmp3.php');</source>
===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.
<source lang="php">$wgFileExtensions[] = 'mp3';</source>
5. [[Configuring file uploads#Set maximum size for file uploads|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.
<source lang="php">$wgMaxUploadSize = '50MB';</source>
* 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. (<strike>Firefox on Linux only!?</strike>)
* 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.
* More than 15 players embedded on a page will not work under Firefox
* Can not recognize Unicode file names
* Files used by FlashMP3 will show up in the Special:Unused Files
* v0.92 (2012-01-20)
** Combatible with MW v1.18.1
* [http://www.mediawiki.org/w/index.php?title=Extension:FlashMP3&oldid=477315 v0.91] (2007-04-03)
** fixed some possible Cross-site scripting vulnerabilities
* [http://www.mediawiki.org/w/index.php?title=Extension:FlashMP3&oldid=80151 v0.9] (2007-03-04)
** added [http://www.last.fm/ last.fm] player
* [http://www.mediawiki.org/w/index.php?title=Extension:FlashMP3&oldid=71365 v0.8] (2007-02-25)
** initial release

Revision as of 08:29, 24 March 2012


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 a label, artist, album or song-level.

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


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
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.

Syntax (default player)

Base Syntax


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

Parameter Reference

Option Effect
autostart=yes The player will automatically open and start to play the track (default value is no)
loop=yes The track will be looped indefinitely (default value is no)
bg=0xHHHHHH Background colour option (where HHHHHH is a valid hexadecimal colour value such as FFFFFF or 009933)
leftbg=0xHHHHHH Left background colour
rightbg=0xHHHHHH Right background colour
rightbghover=0xHHHHHH Right background colour (hover)
lefticon=0xHHHHHH Left icon colour
righticon=0xHHHHHH Right icon colour
righticonhover=0xHHHHHH Right icon colour (hover)
text=0xHHHHHH Text colour
slider=0xHHHHHH Slider colour
loader=0xHHHHHH Loader bar colour
track=0xHHHHHH Progress track colour
border=0xHHHHHH Progress track border colour

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.

<flashmp3 id="2">secondmp3.mp3</flashmp3>



Plays an uploaded mp3-file called mymp3.mp3.


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


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.

Syntax (last.fm player)

Base Syntax

<flashmp3 type="lastfm">resourceID|resourceType|parameter=value|...</flashmp3>

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

Option Effect resourceType
restTitle= The title shown after the player loaded (default value can be set in the PHP code below) all
albumArt= URL of the cover shown after the player loaded (default value can be set in the PHP code below) all
labelName= Name of the label label, playlist
firstTrackName= Name of the first track played (will be shown even before the play button is pressed) artist, album, song
firstArtistName= Name of the first artist played (will be shown even before the play button is pressed) artist, album, song
restDuration= Duration of the track (will be shown even before the play button is pressed) artist, album, song

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


<flashmp3 type="lastfm">11572702|artist</flashmp3>

Plays songs from the given artist (Tookoo).

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

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