/** * returns the currently playing playlist * * @author Ross Carlson * @version 2/9/05 * @since 2/9/05 * @param return Returns the currently playling playlist */ function getCurrentPlaylist() { return getCurPlaylist(); }
/** * Passes a playlist to the jukebox player * * @author Ross Carlson * @version 2/9/05 * @since 2/9/05 * @param $playlist The playlist that we are passing */ function playlist($playlist) { global $include_path, $jbArr, $media_dirs, $jzSERVICES; if (isset($jbArr[$_SESSION['jb_id']]['prefix']) && $jbArr[$_SESSION['jb_id']]['prefix'] == "http") { $content = ""; foreach ($playlist->getList() as $track) { $content .= $track->getFileName("user") . "\n"; } $playlist = $content; } else { $playlist = $jzSERVICES->createPlaylist($playlist, "jukebox"); } $myMpd = _mpdConnection(); // Now let's get our current playlist and current position $curList = getCurPlaylist(true); $curTrack = getCurPlayingTrack(); switch ($_SESSION['jb-addtype']) { case "end": case "current": $restart_playback = false; break; default: $restart_playback = true; } // Ok, now we need to figure out where to add the stuff if ($_SESSION['jb-addtype'] == "current") { // Ok, let's split our first playlist in 2 so we can add in the middle //$begArr = array_slice($curList,0,$curTrack+1); if (is_array($curList)) { $begArr = array(); $endArr = array_slice($curList, $curTrack + 1); } else { $begArr = array(); $endArr = array(); } } else { if ($_SESSION['jb-addtype'] == "begin") { $begArr = array(); $endArr = $curList; } else { if ($_SESSION['jb-addtype'] == "end") { $begArr = array(); $endArr = array(); } else { if ($_SESSION['jb-addtype'] == "replace") { $begArr = array(); $endArr = array(); } } } } if ($restart_playback === true) { $myMpd->Stop(); $myMpd->PLClear(); } else { if ($_SESSION['jb-addtype'] == "current") { // Remove everything at the end of the playlist, since we are going to readd it all. for ($i = sizeof($curList); $i > $curTrack; $i--) { $myMpd->PLRemove($i); } } } // Now let's send the new playlist to the player for ($i = 0; $i < count($begArr); $i++) { // Now let's add this if ($begArr[$i] != '') { $myMpd->PLAdd($begArr[$i]); } } // Ok, Now let's add the new stuff $pArray = explode("\n", $playlist); for ($i = 0; $i < count($pArray); $i++) { if ($pArray[$i] != "") { // Now let's clean up the paths so we can add the media $mArr = explode("|", $media_dirs); $track = trim($pArray[$i]); for ($e = 0; $e < count($mArr); $e++) { if (false !== strpos($track, $mArr[$e])) { $track = trim(str_replace($mArr[$e] . "/", "", $track)); if ($track[0] == '/') { $track = substr($track, 1); } } } $myMpd->PLAdd($track); } } // Now let's finish this out for ($i = 0; $i < count($endArr); $i++) { // Now let's add this if ($endArr[$i] != '') { $myMpd->PLAdd($endArr[$i]); } } // Now let's jump to where we need to play switch ($_SESSION['jb-addtype']) { case "current": if ($curTrack == 0) { $curTrack = -1; } $_POST['jbjumpto'] = $curTrack + 1; break; case "end": $_POST['jbjumpto'] = $curTrack; break; case "replace": case "begin": $_POST['jbjumpto'] = 0; break; } if ($restart_playback) { control("jumpto"); } control("play"); if (defined('NO_AJAX_JUKEBOX')) { ?> <script> history.back(); </script> <?php } exit; }
/** * Returns the currently playing track number * * @author Ross Carlson * @version 2/9/05 * @since 2/9/05 * @param return Returns the currently playling track number */ function getCurPlayingTrack() { global $jbArr; $serv1 = new SCXML(); $serv1->set_host($jbArr[$_SESSION['jb_id']]['server']); $serv1->set_port($jbArr[$_SESSION['jb_id']]['port']); $serv1->set_password($jbArr[$_SESSION['jb_id']]['password']); $serv1->retrieveXML(); $song_title = $serv1->fetchMatchingTag("SONGTITLE"); if (isNothing($song_title)) { return false; } // Ok we need to find the current track then get that out of the playlist so we'll know where we are $pArray = getCurPlaylist(); for ($i = 0; $i < count($pArray); $i++) { // Are we on it? if (stristr($pArray[$i], $song_title)) { $retVal = $i; } } return $retVal; }
/** * Passes a playlist to the jukebox player * * @author Ross Carlson * @version 2/9/05 * @since 2/9/05 * @param $playlist The playlist that we are passing */ function playlist($playlist) { global $include_path, $jbArr, $jzSERVICES; $playlist = $jzSERVICES->createPlaylist($playlist, "jukebox"); // First we need to get the current playlist so we can figure out where to add $curList = getCurPlaylist(); // Let's get where we are in the current list $curTrack = getCurPlayingTrack(); // Ok, now we need to figure out where to add the stuff if ($_SESSION['jb-addtype'] == "current") { // Ok, let's split our first playlist in 2 so we can add in the middle $begArr = array_slice($curList, 0, $curTrack + 1); $endArr = array_slice($curList, $curTrack + 1); } else { if ($_SESSION['jb-addtype'] == "begin") { $begArr = ""; $endArr = array(); } else { if ($_SESSION['jb-addtype'] == "end") { $begArr = $curList; $endArr = array(); } else { if ($_SESSION['jb-addtype'] == "replace") { $begArr = array(); $endArr = array(); } } } } // Now let's send the new playlist to the player $f = false; $data = ""; for ($i = 0; $i < count($begArr); $i++) { // Now let's add this if ($begArr[$i] != "") { $val = "\\\\" . $jbArr[$_SESSION['jb_id']]['mediaserver'] . "\\" . $jbArr[$_SESSION['jb_id']]['mediashare'] . "\\" . str_replace($jbArr[$_SESSION['jb_id']]['localpath'], "", str_replace("/", "\\", $begArr[$i])); //echo $val. "<br>"; if ($f) { $val = "\r\n" . trim($val); } $f = true; $data .= $val; } } // Ok, Now let's add the new stuff $pArray = explode("\n", $playlist); for ($i = 0; $i < count($pArray); $i++) { if ($pArray[$i] != "") { // Now let's add this $val = "\\\\" . $jbArr[$_SESSION['jb_id']]['mediaserver'] . "\\" . $jbArr[$_SESSION['jb_id']]['mediashare'] . str_replace($jbArr[$_SESSION['jb_id']]['localpath'], "", str_replace("/", "\\", $pArray[$i])); //echo $val. "<br>"; if ($f) { $val = "\r\n" . trim($val); } $f = true; $data .= $val; } } // Now let's finish this out for ($i = 0; $i < count($endArr); $i++) { if ($endArr[$i] != "") { // Now let's add this $val = "\\\\" . $jbArr[$_SESSION['jb_id']]['mediaserver'] . "\\" . $jbArr[$_SESSION['jb_id']]['mediashare'] . "\\" . str_replace($jbArr[$_SESSION['jb_id']]['localpath'], "", str_replace("/", "\\", $endArr[$i])); //echo $val. "<br>"; if ($f) { $val = "\r\n" . trim($val); } $f = true; $data .= $val; } } // Now let's clear the current list control("clear", false); usleep(500); $fileName = $jbArr[$_SESSION['jb_id']]['localpath'] . "/" . $jbArr[$_SESSION['jb_id']]['playlistname']; $handle = fopen($fileName, "w"); fwrite($handle, $data); fclose($handle); // Ok, now we need to tell the audiotron to play the M3U file $plName = "\\\\" . $jbArr[0]['mediaserver'] . "\\" . $jbArr[0]['mediashare'] . "\\" . $jbArr[0]['playlistname']; // Now let's play then load file_get_contents("http://" . $jbArr[$_SESSION['jb_id']]['server'] . "/apicmd.asp?cmd=stop"); file_get_contents("http://" . $jbArr[$_SESSION['jb_id']]['server'] . "/apicmd.asp?cmd=clear"); unset($_SESSION['jb_at_playlist']); file_get_contents("http://" . $jbArr[$_SESSION['jb_id']]['server'] . "/apiqfile.asp?type=file&file=" . $plName); usleep(500); file_get_contents("http://" . $jbArr[$_SESSION['jb_id']]['server'] . "/apicmd.asp?cmd=play"); usleep(500); // Ok, first we need to know what track number we are on $c = 0; while ($c < $curTrack + 1) { file_get_contents("http://" . $jbArr[$_SESSION['jb_id']]['server'] . "/apicmd.asp?cmd=next"); usleep(500); $c++; } ?> <script> history.back(); </script> <?php return; }
/** * Passes a playlist to the jukebox player * * @author Ross Carlson * @version 4/9/05 * @since 4/9/05 * @param $playlist The playlist that we are passing */ function playlist($playlist) { global $include_path, $jbArr, $media_dirs, $jzSERVICES; $playlist = $jzSERVICES->createPlaylist($playlist, "jukebox"); // let's connect to the player $jukebox = new slim($jbArr[$_SESSION['jb_id']]['server'], $jbArr[$_SESSION['jb_id']]['port']); // Let's get where we are in the current list $curTrack = getCurPlayingTrack(); // Now let's get the full current playlist $curList = getCurPlaylist(true); // Ok, now we need to figure out where to add the stuff if ($_SESSION['jb-addtype'] == "current") { // Ok, let's split our first playlist in 2 so we can add in the middle $begArr = @array_slice($curList, 0, $curTrack + 1); $endArr = @array_slice($curList, $curTrack + 1); } else { if ($_SESSION['jb-addtype'] == "begin") { $begArr = ""; $endArr = array(); } else { if ($_SESSION['jb-addtype'] == "end") { $begArr = $curList; $endArr = array(); } else { if ($_SESSION['jb-addtype'] == "replace") { $begArr = array(); $endArr = array(); } else { if ($_SESSION['jb-addtype'] == "replace") { $begArr = array(); $endArr = array(); } } } } } // Now let's build the new playlist $prev = false; $curPlaylist = explode("\n", $playlist); if (is_array($begArr) and is_array($endArr)) { $newList = array_merge($begArr, $curPlaylist, $endArr); } else { $prev = true; $newList = explode("\n", $playlist); } $playlist = ""; foreach ($newList as $item) { if ($item != "") { $playlist .= str_replace("/", "\\", $item) . "\n"; } } // Let's stop the jukebox control("stop", false); // let's figure out the filename $fname = "__" . str_replace(":", "_", $jukebox->info['mac'] . ".m3u"); $pl = false; // now let's find where it is $mDirs = explode("|", $media_dirs); foreach ($mDirs as $dir) { if (is_file($dir . "/" . $fname)) { $pl = $dir . "/" . $fname; } } $handle = fopen($pl, "w"); fwrite($handle, $playlist); fclose($handle); // Now let's play it $jukebox->execute("playlist insert " . $fname); control("play"); ?> <script> history.back(); </script> <?php exit; }