break; } $changetime *= 1.05; // some extra changing time echo "_Warn: uhm, the track did not change just now, but I'm not yet through with my -numX. I'll increase the latency to {$changetime}ms and continue like nothing happened.\n"; usleep(1000 * $changetime); // 200ms continue; } break; } $loop--; $prevsong = $song['trackid']; $oldfreq = 0; if (isset($freq[$song['trackid']])) { $oldfreq = $freq[$song['trackid']]['freq']; } $freq[$song['trackid']] = ['freq' => $oldfreq + 1, 'otherprops' => $song]; nextSong(); usleep(1000 * $changetime); // 200ms } if ($argv[1] == '-dumpdb') { foreach ($freq as $trackid => $track) { echo "{$trackid}\t" . $track['otherprops']['trackNumber'] . "\t" . $track['otherprops']['autoRating'] . "\t" . $track['otherprops']['length'] . "\t" . $track['otherprops']['discNumber'] . "\t" . $track['otherprops']['artist'] . "\t" . $track['otherprops']['album'] . "\n"; } exit(0); } foreach ($freq as $trackid => $track) { echo $track['freq'] . ' ' . $track['otherprops']['title'] . "\t{$trackid}\n"; }
} else { if (empty($playToken)) { /* if mix has already been entered and this is the clients first time requesting */ $query = "SELECT tracksCount,playToken,lastUpdate FROM 8tracks_playlists\n WHERE mixId='{$mixId}' \n LIMIT 1"; $result = mysqli_query($con, $query); $row = mysqli_fetch_array($result); $tracksCount = $row["tracksCount"]; /* for when things start to change if ($oldTracksCount < $tracksCount) { $diff = $tracksCount - $oldTracksCount; $s = ($diff == 1 ? ' was' : 's were'); } */ $playToken = $row["playToken"]; $lastUpdate = $row["lastUpdate"]; } else { if (getOutputArray($output, $mixArray, $mixId, $trackNumber, $con)) { /* if there is nothing new in the database, fetch another song... */ nextSong($playToken, $mixId, $trackNumber, $con); } } } getOutputArray($output, $mixArray, $mixId, $trackNumber, $con); // release memory or whatever mysqli_close($con); // add our play token and error status to json $add = array("play_token" => $playToken, "error" => 0); $output = json_encode(array_merge($output, $add)); echo $output;