Exemplo n.º 1
0
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
        }
    }
}
Exemplo n.º 2
0
		</ul>
		
	</div>
	<div id="loading"><h1>LOADING...</h1></div>
	<div id="left">
		<h2 id="breadcrumb"></h2>
		<div class="box" id="info">
		
		</div>
	</div>
	
	<div id="right">
			<div class="box">
				<div class="head">
					<div class="right"><?php 
if (inMpdMode()) {
    echo "<a href=\"#\" onclick=\"playlist_shuffle(); return false;\" title=\"Shuffle This Playlist\">shuffle</a> ";
}
?>
<a href="#" onclick="play('pl',0); return false;" title="Play This Playlist Now">play</a> <a href="#" onclick="savePL('open',0); return false;" title="Save Current Playlist">save</a> <a href="#" onclick="plclear(); return false;"class="red" title="Clear the Current Playlist">clear</a></div>
					<h2 id="pl_title"></h2><span id="pl_info"></span>
				</div>
			<ul id="playlist">
					
			</ul>
			
			<div id="box_extra"> </div>
			</div>
	</div>
	<div class="clear"></div>	
</div>