$sSpopCommand = $sRawCommand; } } } } } } } } if (isset($sSpopCommand)) { // If command is to be passed to spop if (strcmp($sSpopCommand, "") != 0) { sendSpopCommand($spop, $sSpopCommand); } } else { // Else pass command to MPD sendMpdCommand($mpd, $sRawCommand); } } } else { echo json_encode(['service' => 'MPD COMMAND INTERFACE', 'disclaimer' => 'INTERNAL USE ONLY!', 'hosted_on' => gethostname() . ":" . $_SERVER['SERVER_PORT']]); } if ($mpd) { closeMpdSocket($mpd); } if ($spop) { closeSpopSocket($spop); } ?>
function wrk_togglePlayback($redis, $activePlayer) { $stoppedPlayer = $redis->get('stoppedPlayer'); // debug runelog('stoppedPlayer = ', $stoppedPlayer); runelog('activePlayer = ', $activePlayer); if ($stoppedPlayer !== '') { if ($stoppedPlayer === 'MPD') { // connect to MPD daemon $sock = openMpdSocket('/run/mpd.sock', 0); $status = _parseStatusResponse(MpdStatus($sock)); runelog('MPD status', $status); if ($status['state'] === 'pause') { $redis->set('stoppedPlayer', ''); } sendMpdCommand($sock, 'pause'); closeMpdSocket($sock); // debug runelog('sendMpdCommand', 'pause'); } elseif ($stoppedPlayer === 'Spotify') { // connect to SPOPD daemon $sock = openSpopSocket('localhost', 6602, 1); $status = _parseSpopStatusResponse(SpopStatus($sock)); runelog('SPOP status', $status); if ($status['state'] === 'pause') { $redis->set('stoppedPlayer', ''); } sendSpopCommand($sock, 'toggle'); closeSpopSocket($sock); // debug runelog('sendSpopCommand', 'toggle'); } $redis->set('activePlayer', $stoppedPlayer); } else { $redis->set('stoppedPlayer', $activePlayer); wrk_togglePlayback($redis, $activePlayer); } runelog('endFunction!!!', $stoppedPlayer); }