Index: mythweb/modules/music/stream.php
===================================================================
--- mythweb/modules/music/stream.php	(revision 14881)
+++ mythweb/modules/music/stream.php	(working copy)
@@ -41,6 +41,13 @@
                                                             ON ms.directory_id=md.directory_id
                                                WHERE ms.song_id = ?',
                                              $_GET['i']);
+     $songInfo = $db->query_assoc('SELECT s.track, s.name, s.year, a.album_name, b.artist_name
+                FROM music_songs AS s
+                  LEFT JOIN music_albums AS a ON s.album_id=a.album_id
+                  LEFT JOIN music_artists AS b ON a.artist_id=b.artist_id
+                WHERE s.song_id = ?',
+                $_GET[i]);
+
     // Update the play count
         $db->query('UPDATE music_songs
                        SET numplays = numplays + 1
@@ -76,7 +83,7 @@
             $mime = 'audio/mpeg';
             break;
         case 'ogg':
-            $mine = 'application/ogg';
+            $mime = 'application/ogg';
             break;
         default:
             $mime = 'application/octet-stream';
@@ -89,6 +96,50 @@
 // Base music path
     $basepath = setting('MusicLocation', hostname);
 
+    $recodeTo = setting('MusicStreamRecodeBitRate', hostname);
+
+    if ($mime == 'audio/mpeg' && isset($recodeTo) && $recodeTo > 0)
+    {
+        // use lame to recode the file to the required bit-rate.
+        // Local file?
+            if (file_exists("$basepath/$path/$fname")) {
+                $handle = fopen("$basepath/$path/$fname", 'r');
+            }
+        // Otherwise, send it via the backend
+            else {
+                global $Master_Host;
+                $port = _or(get_backend_setting('BackendStatusPort', $Master_Host),
+                            get_backend_setting('BackendStatusPort'));
+                $handle = fopen("http://$Master_Host:$port/Myth/$xml_command?Id=".$xml_id, 'r');
+            }
+
+            $songInfoCmd = '--id3v2-only' .
+                           ' --tt "' . escapeshellcmd($songInfo['name'])        . '"' .
+                           ' --tn "' . escapeshellcmd($songInfo['track'])       . '"' .
+                           ' --ty "' . escapeshellcmd($songInfo['year'])        . '"' .
+                           ' --tl "' . escapeshellcmd($songInfo['album_name'])  . '"' .
+                           ' --ta "' . escapeshellcmd($songInfo['artist_name']) . '"';
+            $desc = array( 0 => array("pipe", "r"),
+                           1 => array("pipe", "w"),
+                           2 => array("pipe", "w") );
+            $pipes = array();
+            $process = proc_open("lame --mp3input -b" . $recodeTo . " --cbr " . $songInfoCmd . " - -", $desc, $pipes);
+
+            if (is_resource($process))
+            {
+                while ($buf = fread($handle, 8192))
+                {
+                    fwrite($pipes[0], $buf);
+                    echo fread($pipes[1], 8192);
+                }
+                fclose($pipes[0]);
+                fclose($pipes[1]);
+                fclose($pipes[2]);
+            }
+            fclose($handle);
+        exit;
+    }
+
 // Local file?
     if (file_exists("$basepath/$path/$fname")) {
         header('Content-Length: '.filesize("$basepath/$path/$fname"));
