-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #623 from hinnerkoetting/feature/optimize-player
Improve webplayer UX
- Loading branch information
Showing
25 changed files
with
1,074 additions
and
575 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
function execAndEcho($command) { | ||
$output = execScript($command); | ||
echo(implode('\n', $output)); | ||
} | ||
|
||
function execScript($command) { | ||
$absoluteCommand = realpath(dirname(__FILE__) .'/../../scripts') ."/{$command}"; | ||
return execSuccessfully($absoluteCommand); | ||
} | ||
|
||
function execScriptWithoutCheck($command) { | ||
$absoluteCommand = realpath(dirname(__FILE__) .'/../../scripts') ."/{$command}"; | ||
exec($absoluteCommand); | ||
} | ||
|
||
function execSuccessfully($command) { | ||
exec($command, $output, $rc); | ||
if ($rc != 0) { | ||
$formattedOutput = implode('\n', $output); | ||
echo "Execution failed\nCommand: {$command}\nOutput: {$formattedOutput}\nRC: .${rc}"; | ||
http_response_code(500); | ||
exit(); | ||
} | ||
return $output; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Returns the cover of the currently played folder. | ||
*/ | ||
|
||
$Audio_Folders_Path = trim(file_get_contents('../../settings/Audio_Folders_Path')); | ||
$Latest_Folder_Played = trim(file_get_contents('../../settings/Latest_Folder_Played')); | ||
|
||
$spover = $Audio_Folders_Path."/../../settings/cover.jpg"; | ||
$ocover = $Audio_Folders_Path."/".$Latest_Folder_Played."/cover.jpg"; | ||
$nocover = "../_assets/img/No_Cover.jpg"; | ||
|
||
if(file_exists($Audio_Folders_Path.'/'.$Latest_Folder_Played.'/cover.jpg')) { | ||
$filename = $ocover; | ||
} elseif (file_exists($Audio_Folders_Path.'/'.$Latest_Folder_Played.'/spotify.txt')) { | ||
$filename = $spover; | ||
} else { | ||
$filename = $nocover; | ||
} | ||
|
||
header("Content-Type: image/jpeg"); | ||
header("Content-Length: " . filesize($filename)); | ||
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); | ||
header("Cache-Control: post-check=0, pre-check=0", false); | ||
header("Pragma: no-cache"); | ||
|
||
$fp = fopen($filename, 'rb'); | ||
fpassthru($fp); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
/** | ||
* Returns the latest played file, folder and playlist. | ||
*/ | ||
|
||
$result = array(); | ||
$result['folder'] = trim(file_get_contents('../../settings/Latest_Folder_Played')); | ||
$result['file'] = trim(file_get_contents('../../settings/Latest_Played_File')); | ||
$result['playlist'] = trim(file_get_contents('../../settings/Latest_Playlist_Played')); | ||
echo json_encode($result, JSON_PRETTY_PRINT); | ||
|
||
header('Content-Type: application/json'); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/*** | ||
* Allows to control the player by sending a command via PUT like 'play' or 'pause'. | ||
* Retrieves information about the player by sending a GET request. | ||
*/ | ||
include 'common.php'; | ||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'PUT') { | ||
handlePut(); | ||
} else if ($_SERVER['REQUEST_METHOD'] === 'GET') { | ||
handleGet(); | ||
} else { | ||
http_response_code(405); | ||
} | ||
|
||
function handlePut() { | ||
$body = file_get_contents('php://input'); | ||
$json = json_decode(trim($body), TRUE); | ||
$inputCommand = $json['command']; | ||
if ($inputCommand != null) { | ||
$controlsCommand = determineCommand($inputCommand); | ||
$execCommand = "playout_controls.sh {$controlsCommand}"; | ||
execScript($execCommand); | ||
} else { | ||
echo "Body is missing command"; | ||
http_response_code(400); | ||
} | ||
} | ||
|
||
function handleGet() { | ||
$statusCommand = "echo 'status\ncurrentsong\nclose' | nc -w 1 localhost 6600"; | ||
$execResult = execSuccessfully($statusCommand); | ||
$result = array(); | ||
forEach($execResult as $value) { | ||
$exploded = explode(' ', $value); | ||
if (count($exploded) == 2) { | ||
$result[substr(trim($exploded[0]), 0, -1)] = $exploded[1]; | ||
} | ||
} | ||
header('Content-Type: application/json'); | ||
echo json_encode($result); | ||
} | ||
|
||
function determineCommand($body) { | ||
switch ($body) { | ||
case 'play': | ||
return '-c=playerplay'; | ||
case 'next': | ||
return '-c=playernext'; | ||
case 'prev': | ||
return '-c=playerprev'; | ||
case 'replay': | ||
return '-c=playerreplay -v=playlist'; | ||
case 'pause': | ||
return '-c=playerpause -v=single'; | ||
case 'repeat': | ||
return '-c=playerprev -c=playerrepeat -v=playlist'; | ||
case 'single': | ||
return '-c=playerprev -c=playerrepeat -v=single'; | ||
case 'repeatoff': | ||
return '-c=playerprev -c=playerrepeat -v=off'; | ||
case 'seekBack': | ||
return '-c=playerprev -c=playerseek -v=-15'; | ||
case 'seekAhead': | ||
return '-c=playerprev -c=playerseek -v=+15'; | ||
case 'stop': | ||
return '-c=playerstop'; | ||
case 'mute': | ||
return'-c=mute'; | ||
case 'volumeup': | ||
return'-c=volumeup'; | ||
case 'volumedown': | ||
return'-c=volumedown'; | ||
} | ||
echo "Unknown command {$body}"; | ||
http_response_code(400); | ||
exit; | ||
} | ||
|
||
?> |
Oops, something went wrong.