--- /dev/null
+{"player":"sudo omxplayer -s -o alsa:plughw:0,1 -y --threshold %Buffer% --no-osd --layer 100 --timeout 3 --aspect-mode stretch '%URL%'","background":"\/home\/pi\/bars\/originalcolorbars480.png","name":"Player #new","volume":"100","buffer":"0.70","url":"udp:\/\/@1.2.3.4:12345","status":"stopped","is_bg":1,"is_boot":1}
\ No newline at end of file
return str_replace("\n", '<br>', `$cmd`);
}
-function read_json_config($filename) {
+function read_json_config($config_filename, $config_default_filename) {
- $json_data = file_get_contents($filename);
- return json_decode($json_data, true);
+ $config_json = file_get_contents($config_filename);
+
+ if ( !$config_json === null || $config_json != '[]' ) {
+ $config = json_decode($config_json, true);
+ } else {
+ $config = array();
+ }
+
+ $defaults = json_decode(file_get_contents($config_default_filename), true);
+ foreach ($defaults as $k => $v) {
+ if ( !isset($config[$k]) ) {
+ $config[$k] = $v;
+ }
+ }
+
+ return $config;
}
#
$player_script = '/tmp/yawep_screen_player_script.sh';
$config_file = 'config.json';
-$config = read_json_config($config_file);
-$default_player_cmd = "sudo omxplayer -s -o alsa:plughw:0,1 -y --threshold %Buffer% --no-osd --layer 100 --timeout 3 --aspect-mode stretch '%URL%'";
+$config = read_json_config($config_file, 'config_default.json');
$screenrc_file = "/tmp/yawep_player_screenrc";
$screenlog_file = "/tmp/yawep_screen.log";
$cron_file = "/etc/cron.d/yawep_player";
$is_boot_checked_html = 'checked="checked"';
}
-if ( $config['player'] == '' ) {
- $config['player'] = $default_player_cmd;
-}
-
if ( isset($_GET['config']) ) {
if ( isset($_GET['volume']) ) {
$config['volume'] = $_GET['volume'];