Integrated mp3 player for mythweb

From MythTV Official Wiki
Revision as of 08:14, 5 April 2007 by Wagnerrp (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The purpose of this modification is two fold:

  • Eliminate the need for a local media player to play music (good for public access machines)
  • Eliminate time spend individually adding URLs to a playlist

The inspiration came from this modification. This mod is no official and is not supported by the authors of MythTV, MythWeb, or MythMusic.

Prerequisites

Required

  • mythtv
  • mythweb
  • mythmusic

Positions given below were on versions 0.20 of each above.

Install a flash mp3 player

The player used for this project is Flash MP3 Player 3.6 by Jeroen Wijering. The XSPF Web Music Player was also tried, and can easily be adapted to this mod.

The player (mp3player.swf) was installed to /mythweb/data and the flash loader (ufo.js) was installed to /mythweb/js.

Load flash loader

Around line 38, add a line to load the flash loader javascript file (UFO.js). ((Box File|/mythweb/modules/_shared/tmpl/default/header.php|

<script type="text/javascript" src="<?php echo root ?>js/ufo.js"></script>

))

Generate Playlist

Inside class mythMusic, function display() ((Box File|/mythweb/modules/music/handler.php|

//Before first if-statement, initialize the playlist
        $file = fopen("data/playlist.xspf","w");
        fwrite($file,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        fwrite($file,"<playlist version=\"0\" xmlns=\"http://xspf.org/ns/0/\">\n");
        fwrite($file," <trackList>\n");

//Inside while loop, write song data
                fwrite($file,"  <track>\n");
                fwrite($file,"   <location>" . $this->urlfilename . "</location>\n");
                fwrite($file,"   <creator>" . $this->artist . "</creator>\n");
                fwrite($file,"   <title>" . $this->title . "</title>\n");
                fwrite($file,"  </track>\n");

//After first if-statement, close the playlist
        fwrite($file," </trackList>\n");
        fwrite($file,"</playlist>\n");
        fclose($file);

))

Load mp3 player

Inside class Theme_music, new function printPlayer() ((Box File|/mythweb/modules/music/tmpl/default/music.php|

    function printPlayer() {
        printf("<p id=\"player2\"><a href=\"http://www.macromedia.com/go/getflashplayer\">Get the Flash Player</a> to see this player.</p>\n");
        printf("<script type=\"text/javascript\">\n");
        printf("  var FU = { movie:\"/mythweb/data/mp3player.swf\",width:\"1000\",height:\"135\",majorversion:\"7\",build:\"0\",bgcolor:\"#265990\",\n");
        printf("      flashvars:\"file=/mythweb/data/playlist.xspf&lightcolor=0x265990&backcolor=0x002650&frontcolor=0xFFFFFF&displayheight=0\" };\n");
        printf("  UFO.create(FU,\"player2\");\n");
        printf("</script>\n");
    }

))

Inside class Theme_music, function print_header() ((Box File|/mythweb/modules/music/tmpl/default/music.php|

//Around line 205, after "$this->printNavBar();"
$this->printPlayer();

))

ToDo

  • Use randomly chosen (or session tagged) filename for playlist to prevent overwriting with multiple simultaneous sessions. Alternatively, have a php script pipe the playlist directly into the flash player.
  • (AFAIK) Flash cannot dynamically size. The best option I see for sizing the width right now is to have a javascript grab the window size and scale the player at reload.