Integrated mp3 player for mythweb

From MythTV Official Wiki
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 spent 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. If not included with the player, UFO can be found here.

Load flash loader

Around line 38, add a line to load the flash loader javascript file (UFO.js).

Php.png /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()

Php.png /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>http://" . $_SERVER['SERVER_NAME'] . $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

Version 1

Player is integrated into the MythWeb Music page.
Inside class Theme_music, new function printPlayer()

Php.png /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()

Php.png /mythweb/modules/music/tmpl/default/music.php

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

Version 2

Player is opened in a separate window.
I didn't like how I had to stay in the same page or else it would halt playback. I moved the player to a separate page that can be reloaded with the current playlist at leisure.

New file, mp3player.html

Script.png /mythweb/data/mp3player.html

<html>
<head>
<script type="text/javascript" src="/mythweb/js/ufo.js"></script>
</head>
<body>
<p id="player2"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<script type="text/javascript">
        var FU = { movie:"/mythweb/data/mp3player.swf",width:"390",height:"388",majorversion:"7",build:"0",bgcolor:"#FFFFFF",
                        flashvars:"file=playlist.xspf&lightcolor=0x265990&backcolor=0x002650&frontcolor=0xFFFFFF&displayheight=0&repeat=list&shuffle
        UFO.create(FU,"player2");
</script>
</body>
</html>

Inside class Theme_music, function print_header()

Php.png /mythweb/modules/music/tmpl/default/music.php

//Around line 185, after "printf("<input TYPE=\"SUBMIT\" NAME=\"updateButton\" VALUE=\"Update\">");"
//Can be moved around wherever desired
printf("<input type=\"button\" value=\"MythWeb Player\" onclick=\"window.open('/mythweb/data/mp3player.html','mythmp3player','width=400,height=400')\">\n");

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. (version 1 only)