Adding Audio Player to ModX

From MODx Wiki

Jump to: navigation, search

This is a guide for enabling the use of the XSPF Flash-based MP3 player in a MODx environment. Credit goes to doze for getting this to work. PHP XML file generation is by sapincher .


Contents

Adding the XSPF Web Music Player to your ModX site

Downloading and Installing the Player

  • Upload the player to your webserver and embed the player on any page you want it to appear, using the Insert/edit embedded media button on the content editor. A good place for this to be uploaded on your server would be assets/xspf_player.

Creating an XML Playlist

  • Create an XML Playlist, following the structure seen below.
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <playlist version="0" xmlns = "http://xspf.org/ns/0/">
  3. <trackList>
  4. <track>
  5. <location>[(site_url)]assets/songs/machinae supremacy - great gianna sisters.mp3</location>
  6. <image>[(site_url)]assets/images/albumcovers_promo.jpg</image>
  7. <annotation>Machinae Supremacy - Great Giana Sisters</annotation>
  8. </track>
  9. <track>
  10. <location>[(site_url)]assets/songs/machinae supremacy - sidology episode 1 - sid evolution (128kbs).mp3</location>
  11. <image>[(site_url)]assets/images/albumcovers_jng.jpg</image>
  12. <annotation>Machinae Supremacy - Sidology Episode 1</annotation>
  13. </track>
  14. <track>
  15. <location>[(site_url)]assets/songs/machinae supremacy - sidology episode 3 - apex ultima (128kbps).mp3</location>
  16. <image>[(site_url)]assets/images/albumcovers_dxm.jpg</image>
  17. <annotation>Machinae Supremacy - Sidology Episode 3</annotation>
  18. </track>
  19. <track>
  20. <location>[(site_url)]assets/songs/machinae supremacy - Sidology 2 Trinity.mp3</location>
  21. <image>[(site_url)]assets/images/albumcovers_redue.jpg</image>
  22. <annotation>Machinae Supremacy - Sidology 2 Trinity</annotation>
  23. </track>
  24. </trackList>
  25. </playlist>
  • You will also need to upload your mp3 files (and images if you are using them) to the directory in which you told the XML file to look for them. If using the above example, you would upload your mp3 files to assets/songs and your cover images to assets/images.

Embedding the XSPF Player in Your Site

  • When you embed your document into your page, it should look like the following:
  1. <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
  2. codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
  3. width="400" height="168" >
  4. <param name="allowScriptAccess" value="sameDomain"/>
  5. <param name="movie" value="[(site_url)]assets/xspf_player/xspf_player.swf"/>
  6. <param name="quality" value="high"/>
  7. <param name="bgcolor" value="#E6E6E6"/>
  8. <param name="wmode" value="transparent"/>
  9. <embed src="[(site_url)]assets/xspf_player/xspf_player.swf?playlist_url=[~17~]"
  10. quality="high" bgcolor="#E6E6E6" name="xspf_player" allowscriptaccess="sameDomain"
  11. type="application/x-shockwave-flash"
  12. pluginspage="http://www.macromedia.com/go/getflashplayer"
  13. align="center" height="168" width="400" wmode="transparent"> </embed>
  14. </object>
  • Please note, that this line :<embed src="[(site_url)]assets/xspf_player/xspf_player.swf?playlist_url=[~17~]" has a playlist_url of [~17~]. This is because 17 is the ID of the playlist document.
  • Also note that the lines <param name="wmode" value="transparent"/> and wmode="transparent" were added to allow a drop down menu to go over top a Flash element. If you don't have a drop down navigation, or it doesn't extend over the Flash area, then you can remove those lines.

PHP-based XML Generation at Runtime

  • It is also possible to dynamically generate a playlist using PHP, so one can simply drop an MP3 file into a folder and let it show up on the XSPF player. In the "assets/songs" folder, create a file named index.php. Inside of that, place:
  1. <?php
  2. $website = "http://your-website-here.com/";
  3. $filetype = "*.mp3";
  4. $filelist = shell_exec( "dir {$filetype} /a-d /b" );
  5. $file_arr = explode( "\n", $filelist );
  6. array_pop( $file_arr ); // last line is always blank
  7. $xml_str = '<?xml version="1.0" encoding="UTF-8"?>
  8. <playlist version="0" xmlns="http://xspf.org/ns/0/">
  9. <trackList>
  10. ';
  11. foreach($file_arr as $key => $value){
  12. $value=substr(stripslashes($value),0,-4);
  13. $song_name_exp = explode("_",$value);
  14. $artist = $song_name_exp[0];
  15. $title = $song_name_exp[1];
  16. $xml_str .= '<track><location>'.$website.'assets/songs/'.$value.'.mp3</location>';
  17. if(is_file('../images/'.$value.'.jpg')){
  18. $xml_str.='<image>'.$website.'/assets/images/'.$value.'.jpg</image>';
  19. }
  20. $xml_str.= '<annotation>'.$artist.' - '.$title.'</annotation></track>'."\n";
  21. }
  22. $xml_str.='</trackList></playlist>';
  23. echo $xml_str;
  24. ?>
  • Note that this relies on the naming convention of your-website-here.com/assets/songs/The Artist_The Title.mp3 . Thus, the system will break if underscores are used in song artists/titles!
  • If there is album art associated with a song, place it in the assets/images folder with the same filename as the song itself, but with a .jpg extension instead of an .mp3 .
  • Another limitation of this feature is the use of shell_exec(), which requires a Linux-based server to utilise.
  • You must also tell XSPF to use this file as the playlist_url, so replace "[~17~]" in the previous example with "[(site_url)]assets/songs".
Personal tools