Example #1
0
function play($mode, $type, $id)
{
    mp3act_connect();
    $tmp = '';
    $query = '';
    if ($mode == 'streaming') {
        session_cache_limiter('nocache');
        header("Content-Type: application/xspf+xml;");
        header("Content-Disposition: inline; filename=\"playlist.xspf\"");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: nocache");
        $tmp .= '<?xml version="1.0" encoding="UTF-8"?><playlist version="1" xmlns="http://xspf.org/ns/0/">' . "\n<trackList>\n";
        if ($type == 'song') {
            $query = "SELECT mp3act_songs.song_id,mp3act_artists.artist_name,mp3act_artists.prefix,mp3act_songs.name,mp3act_songs.length,mp3act_albums.album_art FROM mp3act_songs,mp3act_artists,mp3act_albums WHERE mp3act_songs.song_id={$id} AND mp3act_albums.album_id = mp3act_songs.album_id AND mp3act_artists.artist_id=mp3act_songs.artist_id";
        } elseif ($type == 'album') {
            $query = "SELECT mp3act_songs.song_id,mp3act_artists.artist_name,mp3act_songs.name,mp3act_artists.prefix,mp3act_songs.length,mp3act_albums.album_art FROM mp3act_songs,mp3act_artists,mp3act_albums WHERE mp3act_artists.artist_id=mp3act_songs.artist_id AND mp3act_albums.album_id = mp3act_songs.album_id AND mp3act_songs.album_id={$id} ORDER BY mp3act_songs.track";
        } elseif ($type == 'pl') {
            $query = "SELECT mp3act_songs.song_id,mp3act_artists.artist_name,mp3act_songs.name,mp3act_artists.prefix,mp3act_songs.length,mp3act_albums.album_art FROM mp3act_songs,mp3act_artists,mp3act_playlist,mp3act_albums WHERE mp3act_artists.artist_id=mp3act_songs.artist_id AND mp3act_songs.song_id=mp3act_playlist.song_id AND mp3act_albums.album_id = mp3act_songs.album_id AND mp3act_playlist.user_id={$_SESSION['sess_userid']} AND mp3act_playlist.private=1 ORDER BY mp3act_playlist.pl_id";
        }
        $result = mysql_query($query);
        while ($row = mysql_fetch_array($result)) {
            $length = $row['length'];
            if (getSystemSetting("sample_mode") == 1) {
                $length = floor($row['length'] / 4);
            }
            $tmp .= "<track>\n";
            $tmp .= "\t<creator>{$row['artist_name']}</creator><title>{$row['name']}</title>\n";
            $tmp .= "\t<location>{$GLOBALS['http_url']}{$GLOBALS['uri_path']}/playstream.php?i={$row['song_id']}&u={$_SESSION['sess_usermd5']}&b={$_SESSION['sess_bitrate']}&s={$_SESSION['sess_stereo']}</location>\n";
            $tmp .= "\t<meta rel=\"type\">mp3</meta>\n";
            $tmp .= "\t<image>{$GLOBALS['http_url']}{$GLOBALS['uri_path']}/art/{$row['album_art']}</image>\n";
            $tmp .= "</track>\n";
        }
        $tmp .= "   </trackList></playlist>\n";
        return $tmp;
        exit;
    } else {
        switch ($type) {
            case 'stop':
                //exec("killall -c ".basename(getSystemSetting("phpbin"))." > /dev/null 2>&1 &");
                //exec("killall -c ".basename(getSystemSetting("mp3bin"))." > /dev/null 2>&1 &");
                killCmd("play.php");
                killCmd(basename(getSystemSetting("mp3bin")));
                //submitScrobbler($_SESSION['sess_userid']);
                if (file_exists("/tmp/mp3act")) {
                    unlink("/tmp/mp3act");
                }
                $query = "UPDATE mp3act_songs SET random=0";
                mysql_query($query);
                $query = "DELETE FROM mp3act_currentsong";
                mysql_query($query);
                break;
            case 'prev':
                // PREV is not working...
                /*exec("killall ".getSystemSetting("phpbin")." > /dev/null 2>&1 &");
                	 exec("killall ".getSystemSetting("mp3bin")." > /dev/null 2>&1 &");
                	 $query = "DELETE FROM mp3act_currentsong";
                		mysql_query($query);
                	 exec(getSystemSetting("phpbin")." includes/play.php 3 $id > /dev/null 2>&1 &"); 
                	 */
                break;
            case 'next':
                //exec("killall -c ".basename(getSystemSetting("mp3bin"))." > /dev/null 2>&1 &");
                killCmd(basename(getSystemSetting("mp3bin")));
                break;
            case 'song':
                if (!file_exists("/tmp/mp3act")) {
                    touch("/tmp/mp3act");
                    exec(getSystemSetting("phpbin") . " includes/play.php 1 {$_SESSION['sess_userid']} {$id} > /dev/null 2>&1 &");
                }
                break;
            case 'album':
                if (!file_exists("/tmp/mp3act")) {
                    touch("/tmp/mp3act");
                    exec(getSystemSetting("phpbin") . " includes/play.php 2 {$_SESSION['sess_userid']} {$id} > /dev/null 2>&1 &");
                }
                break;
            case 'pl':
                if (!file_exists("/tmp/mp3act")) {
                    touch("/tmp/mp3act");
                    exec(getSystemSetting("phpbin") . " includes/play.php 3 {$id} > /dev/null 2>&1 &");
                }
                break;
        }
        // END JUKEBOX MODE
    }
}
function play($mode, $type, $id)
{
    global $mpd;
    if ($mode == 'streaming') {
        mp3act_connect();
        $tmp = '';
        $query = '';
        session_cache_limiter('nocache');
        header("Content-Type: audio/mpegurl;");
        header("Content-Disposition: inline; filename=\"playlist.m3u\"");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: nocache");
        $tmp .= "#EXTM3U\n";
        if ($type == 'song') {
            $query = "SELECT mp3act_songs.song_id,mp3act_artists.artist_name,mp3act_artists.prefix,mp3act_songs.name,mp3act_songs.length FROM mp3act_songs,mp3act_artists WHERE mp3act_songs.song_id={$id} AND mp3act_artists.artist_id=mp3act_songs.artist_id";
        } elseif ($type == 'album') {
            $query = "SELECT mp3act_songs.song_id,mp3act_artists.artist_name,mp3act_songs.name,mp3act_artists.prefix,mp3act_songs.length FROM mp3act_songs,mp3act_artists WHERE mp3act_artists.artist_id=mp3act_songs.artist_id AND mp3act_songs.album_id={$id} ORDER BY mp3act_songs.track";
        } elseif ($type == 'pl') {
            $query = "SELECT mp3act_songs.song_id,mp3act_artists.artist_name,mp3act_songs.name,mp3act_artists.prefix,mp3act_songs.length FROM mp3act_songs,mp3act_artists,mp3act_playlist WHERE mp3act_artists.artist_id=mp3act_songs.artist_id AND mp3act_songs.song_id=mp3act_playlist.song_id AND mp3act_playlist.user_id={$_SESSION['sess_userid']} AND mp3act_playlist.private=1 ORDER BY mp3act_playlist.pl_id";
        }
        $result = mysql_query($query);
        while ($row = mysql_fetch_array($result)) {
            $length = $row['length'];
            if (getSystemSetting("sample_mode") == 1) {
                $length = floor($row['length'] / 4);
            }
            $tmp .= "#EXTINF:{$length},{$row['prefix']} {$row['artist_name']} - {$row['name']}\n";
            $tmp .= "{$GLOBALS['http_url']}{$GLOBALS['uri_path']}/playstream.php?i={$row['song_id']}&u={$_SESSION['sess_usermd5']}&b={$_SESSION['sess_bitrate']}&s={$_SESSION['sess_stereo']}\n";
        }
        return $tmp;
        exit;
    } else {
        if (accessLevel(7)) {
            // check for MPD mode
            if (inMpdMode()) {
                if (mpd_connect() == 0) {
                    return;
                }
                // MPD jukebox
                switch ($type) {
                    case 'stop':
                        // stop MPD
                        $mpd->Stop();
                        break;
                    case 'prev':
                        // mpd.prev
                        $mpd->Previous();
                        break;
                    case 'next':
                        // mpd.next
                        $mpd->Next();
                        break;
                    case 'song':
                        // stop mpd, clear the playlist, load this song then play
                        $mpd->Stop();
                        $mpd->PLClear();
                        // $id is the song_id to load
                        $song = mpdGetSongForId($id);
                        $mpd->PLAdd($song['file']);
                        // play
                        $mpd->Play();
                        break;
                    case 'album':
                        // stop mpd, clear the playlist, load this album then play
                        $mpd->Stop();
                        $mpd->PLClear();
                        list($artist, $album) = mpdGetArtistAlbumForAlbumId($id);
                        // now do a "find album XXX"
                        // then filter for our artist
                        if (!is_null($ar = $mpd->Find(MPD_SEARCH_ALBUM, $album))) {
                            // got results, iterate and filter for the right artist
                            if (count($ar) > 0) {
                                foreach ($ar as $track) {
                                    if ($track['Artist'] == $artist) {
                                        $localplaylist[] = $track;
                                    }
                                }
                            }
                        }
                        // let's do a bulk add
                        if (count($localplaylist) > 0) {
                            foreach ($localplaylist as $plentry) {
                                $bulkadd[] = $plentry['file'];
                            }
                        }
                        $mpd->PLAddBulk($bulkadd);
                        // play
                        $mpd->Play();
                        break;
                    case 'pl':
                        // play the playlist
                        $mpd->Play();
                        break;
                }
            } else {
                // local jukebox
                mp3act_connect();
                $tmp = '';
                $query = '';
                switch ($type) {
                    case 'stop':
                        //exec("killall -c ".basename(getSystemSetting("phpbin"))." > /dev/null 2>&1 &");
                        //exec("killall -c ".basename(getSystemSetting("mp3bin"))." > /dev/null 2>&1 &");
                        killCmd("play.php");
                        killCmd(basename(getSystemSetting("mp3bin")));
                        //submitScrobbler($_SESSION['sess_userid']);
                        if (file_exists("/tmp/mp3act")) {
                            unlink("/tmp/mp3act");
                        }
                        $query = "UPDATE mp3act_songs SET random=0";
                        mysql_query($query);
                        $query = "DELETE FROM mp3act_currentsong";
                        mysql_query($query);
                        break;
                    case 'prev':
                        // PREV is not working...
                        /*exec("killall ".getSystemSetting("phpbin")." > /dev/null 2>&1 &");
                        	 exec("killall ".getSystemSetting("mp3bin")." > /dev/null 2>&1 &");
                        	 $query = "DELETE FROM mp3act_currentsong";
                        		mysql_query($query);
                        	 exec(getSystemSetting("phpbin")." includes/play.php 3 $id > /dev/null 2>&1 &"); 
                        	 */
                        break;
                    case 'next':
                        //exec("killall -c ".basename(getSystemSetting("mp3bin"))." > /dev/null 2>&1 &");
                        killCmd(basename(getSystemSetting("mp3bin")));
                        break;
                    case 'song':
                        if (!file_exists("/tmp/mp3act")) {
                            touch("/tmp/mp3act");
                            exec(getSystemSetting("phpbin") . " includes/play.php 1 {$_SESSION['sess_userid']} {$id} > /tmp/play.debug 2>&1 &");
                        }
                        break;
                    case 'album':
                        if (!file_exists("/tmp/mp3act")) {
                            touch("/tmp/mp3act");
                            exec(getSystemSetting("phpbin") . " includes/play.php 2 {$_SESSION['sess_userid']} {$id} > /tmp/play.debug 2>&1 &");
                        }
                        break;
                    case 'pl':
                        if (!file_exists("/tmp/mp3act")) {
                            touch("/tmp/mp3act");
                            exec(getSystemSetting("phpbin") . " includes/play.php 3 {$id} > /tmp/play.debug 2>&1 &");
                        }
                        break;
                }
                // local jukebox
            }
            // END JUKEBOX MODE
        }
    }
}
function play($mode, $type, $id)
{
    mp3act_connect();
    $tmp = '';
    $query = '';
    if ($mode == 'streaming') {
        session_cache_limiter('nocache');
        header("Content-Type: audio/mpegurl;");
        header("Content-Disposition: inline; filename=\"playlist.m3u\"");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: nocache");
        $tmp .= "#EXTM3U\n";
        if ($type == 'song') {
            $query = "SELECT mp3act_songs.song_id,mp3act_artists.artist_name,mp3act_artists.prefix,mp3act_songs.name,mp3act_songs.length FROM mp3act_songs,mp3act_artists WHERE mp3act_songs.song_id={$id} AND mp3act_artists.artist_id=mp3act_songs.artist_id";
        } elseif ($type == 'album') {
            $query = "SELECT mp3act_songs.song_id,mp3act_artists.artist_name,mp3act_songs.name,mp3act_artists.prefix,mp3act_songs.length FROM mp3act_songs,mp3act_artists WHERE mp3act_artists.artist_id=mp3act_songs.artist_id AND mp3act_songs.album_id={$id} ORDER BY mp3act_songs.track";
        } elseif ($type == 'pl') {
            $query = "SELECT mp3act_songs.song_id,mp3act_artists.artist_name,mp3act_songs.name,mp3act_artists.prefix,mp3act_songs.length FROM mp3act_songs,mp3act_artists,mp3act_playlist WHERE mp3act_artists.artist_id=mp3act_songs.artist_id AND mp3act_songs.song_id=mp3act_playlist.song_id AND mp3act_playlist.user_id={$_SESSION['sess_userid']} AND mp3act_playlist.private=1 ORDER BY mp3act_playlist.pl_id";
        }
        $result = mysql_query($query);
        while ($row = mysql_fetch_array($result)) {
            $length = $row['length'];
            if (getSystemSetting("sample_mode") == 1) {
                $length = floor($row['length'] / 4);
            }
            $tmp .= "#EXTINF:{$length},{$row['prefix']} {$row['artist_name']} - {$row['name']}\n";
            $tmp .= "{$GLOBALS['http_url']}{$GLOBALS['uri_path']}/playstream.php?i={$row['song_id']}&u={$_SESSION['sess_usermd5']}&b={$_SESSION['sess_bitrate']}&s={$_SESSION['sess_stereo']}\n";
        }
        return $tmp;
        exit;
    } else {
        switch ($type) {
            case 'stop':
                //exec("killall -c ".basename(getSystemSetting("phpbin"))." > /dev/null 2>&1 &");
                //exec("killall -c ".basename(getSystemSetting("mp3bin"))." > /dev/null 2>&1 &");
                killCmd("play.php");
                killCmd(basename(getSystemSetting("mp3bin")));
                //submitScrobbler($_SESSION['sess_userid']);
                if (file_exists("/tmp/mp3act")) {
                    unlink("/tmp/mp3act");
                }
                $query = "UPDATE mp3act_songs SET random=0";
                mysql_query($query);
                $query = "DELETE FROM mp3act_currentsong";
                mysql_query($query);
                break;
            case 'prev':
                // PREV is not working...
                /*exec("killall ".getSystemSetting("phpbin")." > /dev/null 2>&1 &");
                	 exec("killall ".getSystemSetting("mp3bin")." > /dev/null 2>&1 &");
                	 $query = "DELETE FROM mp3act_currentsong";
                		mysql_query($query);
                	 exec(getSystemSetting("phpbin")." includes/play.php 3 $id > /dev/null 2>&1 &"); 
                	 */
                break;
            case 'next':
                //exec("killall -c ".basename(getSystemSetting("mp3bin"))." > /dev/null 2>&1 &");
                killCmd(basename(getSystemSetting("mp3bin")));
                break;
            case 'song':
                if (!file_exists("/tmp/mp3act")) {
                    touch("/tmp/mp3act");
                    exec(getSystemSetting("phpbin") . " includes/play.php 1 {$_SESSION['sess_userid']} {$id} > /dev/null 2>&1 &");
                }
                break;
            case 'album':
                if (!file_exists("/tmp/mp3act")) {
                    touch("/tmp/mp3act");
                    exec(getSystemSetting("phpbin") . " includes/play.php 2 {$_SESSION['sess_userid']} {$id} > /dev/null 2>&1 &");
                }
                break;
            case 'pl':
                if (!file_exists("/tmp/mp3act")) {
                    touch("/tmp/mp3act");
                    exec(getSystemSetting("phpbin") . " includes/play.php 3 {$id} > /dev/null 2>&1 &");
                }
                break;
        }
        // END JUKEBOX MODE
    }
}