Skip to content

Commit c7d073e

Browse files
committed
Improve code for renderer metadata display
- Consolidate redundant code so spotify and deezer can use the same css and js - Some fixes for layout and position of the buttons
1 parent 01983fc commit c7d073e

File tree

5 files changed

+71
-104
lines changed

5 files changed

+71
-104
lines changed

www/css/media.css

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,9 @@ body {
123123

124124
/* Renderer active overlays: Text and button */
125125
#inpsrc-indicator {font-size:3.5em;}
126-
#inpsrc-msg {top:70%;width:100%}
127-
#inpsrc-spotmeta,
128-
#inpsrc-deezmeta {position:relative;margin-bottom:3em;}
129-
.inpsrc-spotmeta-backdrop,
130-
.inpsrc-deezmeta-backdrop {height:auto;}
126+
#inpsrc-msg {top:50%;width:100%}
127+
#inpsrc-metadata {position:relative;}
128+
.inpsrc-metadata-backdrop {height:auto;}
131129

132130
/* Shutdown, Restart, Reconnect */
133131
.reconnect-btn {font-size:2em;}
@@ -358,11 +356,11 @@ body {
358356

359357
/* Renderer active overlays: Text and button */
360358
#inpsrc-indicator {font-size:2.85em;}
361-
#inpsrc-spotmeta,
362-
#inpsrc-deezmeta {font-size:.5em;}
363-
#inpsrc-msg i,
364-
#inpsrc-spotmeta-refresh i,
365-
#inpsrc-deezmeta-refresh i {font-size:1.25em;}
359+
#inpsrc-metadata {font-size:.5em;}
360+
#inpsrc-metadata-refresh {padding-bottom:calc(.5em + env(safe-area-inset-bottom));}
361+
#inpsrc-metadata-refresh i,
362+
#inpsrc-msg i {font-size:1.25em;}
363+
366364
/* For the configs */
367365
#panel-header,
368366
.container {margin-left:calc(env(safe-area-inset-left) + 1rem);}

www/css/panels.css

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,19 @@ html {background-color:inherit;}
9090
.inpsrc {position:fixed;z-index:9999;backdrop-filter: blur(5px);-webkit-backdrop-filter:blur(5px);overflow:hidden;color:var(--adapttext);background-color:var(--modalbkdr);display:none;}
9191
#inpsrc-indicator {font-size:1.85em;width:100vw;height:100vh;text-align:center;}
9292
/* Input source name */
93-
#inpsrc-msg {animation:fadeIn var(--fadein-rate);}
93+
#inpsrc-msg {animation:fadeIn var(--fadein-rate);padding-bottom:.5em;}
9494
.inpsrc-msg-default {padding:0;margin:0;transform:translate(-50%, -50%);top:50%;left:50%;position:fixed;width:100%;}
95-
.inpsrc-msg-spotify {position:absolute;bottom:0;z-index:9999;}
95+
.inpsrc-msg-metadata {position:absolute;bottom:0;z-index:9999;}
9696
#inpsrc-msg a,
97-
#inpsrc-spotmeta-refresh a,
98-
#inpsrc-deezmeta-refresh a {color:#eee;}
97+
#inpsrc-metadata-refresh a {color:#eee;}
9998
#inpsrc-msg i,
100-
#inpsrc-spotmeta-refresh i,
101-
#inpsrc-deezmeta-refresh i {font-size:1.5em;}
99+
#inpsrc-metadata-refresh i {font-size:1.5em;}
102100
#inpsrc-msg-text {display:block;font-size:1em;margin-bottom:0.5em;}
103101
/* Volume control */
104102
#inpsrc-preamp-volume, #multiroom-receiver-volume {font-size:.7em !important;}
105103
/* Spotify backdrop cover and metadata */
106-
.inpsrc-spotmeta-backdrop,
107-
.inpsrc-deezmeta-backdrop {height:calc(88vh - .5rem);}
108-
#inpsrc-spotmeta,
109-
#inpsrc-deezmeta {
104+
.inpsrc-metadata-backdrop {height:calc(88vh - .5rem);}
105+
#inpsrc-metadata {
110106
position:absolute;
111107
display:block;
112108
height: 12vh;
@@ -117,19 +113,16 @@ html {background-color:inherit;}
117113
font-weight:500;
118114
background:linear-gradient(to right, rgba(64,64,64,0.5), rgba(0,0,0,1) 50%, rgba(64,64,64,.5));
119115
}
120-
#inpsrc-spotmeta span,
121-
#inpsrc-deezmeta span {font-size:.75em;font-weight:400;}
122-
#inpsrc-spotmeta-refresh,
123-
#inpsrc-deezmeta-refresh {position:absolute;bottom:0;z-index:9999;right:0;float:right;}
116+
#inpsrc-metadata span {font-size:.75em;font-weight:400;}
117+
#inpsrc-metadata-refresh {position:absolute;bottom:0;z-index:9999;right:0;float:right;}
124118

125119
/* Buttons */
126120
.audioinfo-renderer,
127121
.configure-renderer,
128122
.disconnect-renderer,
129123
.turnoff-renderer,
130124
.turnoff-receiver {border-radius:5rem;background-color:var(--btnshade4);margin:0.2em 1vw;padding:0.5rem 0;font-size:.7em;width:10em;color:inherit;}
131-
.spotify-renderer,
132-
.deezer-renderer {border-radius:5rem;background-color:transparent;padding:1em 0;font-size:.6em;width:3em;color:inherit;}
125+
.renderer-btn {border-radius:5rem;background-color:transparent;padding:1em 0;font-size:.6em;width:3em;color:inherit;}
133126

134127
/* Mask hover effect */
135128
.audioinfo-renderer:hover,

www/header.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,8 @@
143143
<div id="inpsrc-indicator" class="inpsrc">
144144
<div id="inpsrc-backdrop"></div>
145145
<div id="inpsrc-msg" class="inpsrc-msg-default"></div>
146-
<div id="inpsrc-spotmeta"></div>
147-
<div id="inpsrc-spotmeta-refresh"></div>
148-
<div id="inpsrc-deezmeta"></div>
149-
<div id="inpsrc-deezmeta-refresh"></div>
146+
<div id="inpsrc-metadata"></div>
147+
<div id="inpsrc-metadata-refresh"></div>
150148
</div>
151149

152150
<!-- HEADER -->

www/inc/renderer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ function startDeezer() {
169169
}
170170

171171
// Output device
172-
// NOTE: Specifying Loopback instead of _audioout when Multiroom TX is On greatly reduces audio glitches
173-
$device = $_SESSION['audioout'] == 'Local' ? ($_SESSION['multiroom_tx'] == 'On' ? 'plughw:Loopback,0' : '_audioout') : 'btstream';
172+
$device = $_SESSION['audioout'] == 'Local' ? '_audioout' : 'btstream';
174173

175174
// Options
176175
$volume_normalization = $cfgDeezer['normalize_volume'] == 'Yes' ? ' --normalize-volume' : '';

www/js/playerlib.js

Lines changed: 51 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -549,31 +549,26 @@ function engineCmd() {
549549
break;
550550
case 'spotactive1':
551551
case 'spotactive0':
552-
inpSrcIndicator(cmd[0],
553-
'<span id="inpsrc-msg-text">Spotify Active</span>' +
554-
'<button class="btn spotify-renderer disconnect-spotify" data-job="spotifysvc"><i class="fa-regular fa-sharp fa-xmark"></i></button>' +
555-
receiversBtn(cmd[0]) +
556-
audioInfoBtn(cmd[0]) +
557-
'<a id="inpsrc-spotify-refresh" class="btn spotify-renderer" href="javascript:refreshSpotmeta()"><i class="fa-regular fa-sharp fa-redo"></i></a>'
558-
);
559-
$('#inpsrc-spotmeta-refresh').html('');
560-
break;
561-
case 'update_spotmeta':
562-
updateSpotmeta(cmd[1]);
563-
break;
564552
case 'deezactive1':
565553
case 'deezactive0':
566-
inpSrcIndicator(cmd[0],
567-
'<span id="inpsrc-msg-text">Deezer Active</span>' +
568-
'<button class="btn deezer-renderer disconnect-deezer" data-job="deezersvc"><i class="fa-regular fa-sharp fa-xmark"></i></button>' +
554+
var rendererName = cmd[0].includes('spot') ? 'spotify' : 'deezer';
555+
inpSrcIndicator(cmd[0],
556+
'<span id="inpsrc-msg-text">' +
557+
rendererName.charAt(0).toUpperCase() + rendererName.slice(1) +
558+
' Active</span>' +
559+
'<button class="btn renderer-btn disconnect-' +
560+
rendererName +
561+
'" data-job="' +
562+
rendererName + 'svc"><i class="fa-regular fa-sharp fa-xmark"></i></button>' +
569563
receiversBtn(cmd[0]) +
570564
audioInfoBtn(cmd[0]) +
571-
'<a id="inpsrc-deezer-refresh" class="btn deezer-renderer" href="javascript:refreshDeezmeta()"><i class="fa-regular fa-sharp fa-redo"></i></a>'
565+
rendererRefreshBtn()
572566
);
573-
$('#inpsrc-deezmeta-refresh').html('');
567+
$('#inpsrc-metadata-refresh').html('');
574568
break;
569+
case 'update_spotmeta':
575570
case 'update_deezmeta':
576-
updateDeezmeta(cmd[1]);
571+
updateInpsrcMeta(cmd[0], cmd[1]); // cmd[1]: metadata
577572
break;
578573
case 'slactive1':
579574
case 'slactive0':
@@ -750,9 +745,10 @@ function engineCmdLite() {
750745

751746
function inpSrcIndicator(cmd, msgText) {
752747
UI.currentFile = 'blank';
753-
$('#inpsrc-msg').removeClass('inpsrc-msg-spotify');
748+
$('#inpsrc-msg').removeClass('inpsrc-msg-metadata');
754749
$('#inpsrc-msg').addClass('inpsrc-msg-default');
755-
$('#inpsrc-spotmeta').html('');
750+
$('#inpsrc-msg').css({width:'100%', top:'50%', bottom:'unset'});
751+
$('#inpsrc-metadata').hide();
756752

757753
// Set custom backdrop (if any)
758754
if (SESSION.json['renderer_backdrop'] == 'Yes') {
@@ -783,64 +779,37 @@ function inpSrcIndicator(cmd, msgText) {
783779
}
784780
}
785781

786-
function refreshSpotmeta() {
787-
$.getJSON('command/renderer.php?cmd=get_spotmeta', function(data) {
788-
updateSpotmeta(data);
782+
function refreshInpsrcMeta() {
783+
cmd = SESSION.json['spotactive'] == '1' ? 'get_spotmeta' : 'get_deezmeta';
784+
$.getJSON('command/renderer.php?cmd=' + cmd, function(data) {
785+
updateInpsrcMeta(cmd, data);
789786
});
790787
}
791-
function updateSpotmeta(data) {
788+
function updateInpsrcMeta(cmd, data) {
792789
$('#inpsrc-msg').removeClass('inpsrc-msg-default');
793-
$('#inpsrc-msg').addClass('inpsrc-msg-spotify');
790+
$('#inpsrc-msg').addClass('inpsrc-msg-metadata');
794791
$('#inpsrc-msg-text').text('');
795792

796793
$('#inpsrc-backdrop').css('filter', 'blur(0px)');
797794
$('#inpsrc-backdrop').css('transform', 'scale(1.0)');
798795

799-
// data = title;artists;album;duration;coverurl (note duration is in ms)
800-
//DEBUG:console.log(data);
796+
// Spotify: title;artists;album;duration;coverurl (duration is in ms)
797+
// Deezer: title;artist;album;duration;coverurl (duration is in secs)
801798
var metadata = data.split(';');
802-
$('#inpsrc-backdrop').html('<img class="inpsrc-spotmeta-backdrop" ' + 'src="' + metadata[4] + '">');
803-
$('#inpsrc-spotmeta').html(
804-
metadata[0] + ' (' + formatSongTime(Math.round(parseInt(metadata[3]) / 1000)) + ')' +
805-
'<br>' + '<span>' + metadata[1] + '<br>' + metadata[2] + '</span>'
806-
);
807-
808-
if (window.matchMedia("(orientation: portrait)").matches) {
809-
$('#inpsrc-spotmeta-refresh').html('');
810-
} else {
811-
$('#inpsrc-spotify-refresh').html('');
812-
$('#inpsrc-spotmeta-refresh').html('<a class="btn spotify-renderer" href="javascript:refreshSpotmeta()"><i class="fa-regular fa-sharp fa-redo"></i></a>');
813-
}
814-
}
799+
var timeDivisor = (cmd == 'get_spotmeta' || cmd == 'update_spotmeta') ? 1000 : 1;
815800

816-
function refreshDeezmeta() {
817-
$.getJSON('command/renderer.php?cmd=get_deezmeta', function(data) {
818-
updateDeezmeta(data);
819-
});
820-
}
821-
function updateDeezmeta(data) {
822-
$('#inpsrc-msg').removeClass('inpsrc-msg-default');
823-
$('#inpsrc-msg').addClass('inpsrc-msg-spotify');
824-
$('#inpsrc-msg-text').text('');
825-
826-
$('#inpsrc-backdrop').css('filter', 'blur(0px)');
827-
$('#inpsrc-backdrop').css('transform', 'scale(1.0)');
828-
829-
// data = title;artist;album;duration;coverurl (note duration is in secs)
830-
//DEBUG:console.log(data);
831-
var metadata = data.split(';');
832-
$('#inpsrc-backdrop').html('<img class="inpsrc-deezmeta-backdrop" ' + 'src="' + metadata[4] + '">');
833-
$('#inpsrc-deezmeta').html(
834-
metadata[0] + ' (' + formatSongTime(Math.round(parseInt(metadata[3]))) + ')' +
801+
$('#inpsrc-backdrop').html('<img class="inpsrc-metadata-backdrop" ' + 'src="' + metadata[4] + '">');
802+
$('#inpsrc-metadata').html(
803+
metadata[0] + ' (' + formatSongTime(Math.round(parseInt(metadata[3]) / timeDivisor)) + ')' +
835804
'<br>' + '<span>' + metadata[1] + '<br>' + metadata[2] + '</span>'
836805
);
837806

838-
if (window.matchMedia("(orientation: portrait)").matches) {
839-
$('#inpsrc-deezmeta-refresh').html('');
840-
} else {
841-
$('#inpsrc-deezer-refresh').html('');
842-
$('#inpsrc-deezmeta-refresh').html('<a class="btn deezer-renderer" href="javascript:refreshDeezmeta()"><i class="fa-regular fa-sharp fa-redo"></i></a>');
843-
}
807+
inpSrcMetaRefreshBtn();
808+
809+
$('#inpsrc-metadata').show();
810+
// Add !important ?
811+
$('#inpsrc-msg').css({width:'unset', top:'unset', bottom:'0', 'margin-bottom':'calc(.5em + env(safe-area-inset-bottom))'});
812+
$('#inpsrc-metadata-refresh').css('padding-bottom', 'calc(.5em + env(safe-area-inset-bottom)');
844813
}
845814

846815
// Show/hide CoverView screen saver
@@ -1407,13 +1376,13 @@ function renderUI() {
14071376
if (SESSION.json['spotactive'] == '1') {
14081377
inpSrcIndicator('spotactive1',
14091378
'<span id="inpsrc-msg-text">Spotify Active</span>' +
1410-
'<button class="btn spotify-renderer disconnect-spotify" data-job="spotifysvc"><i class="fa-regular fa-sharp fa-xmark"></i></button>' +
1379+
'<button class="btn renderer-btn disconnect-spotify" data-job="spotifysvc"><i class="fa-regular fa-sharp fa-xmark"></i></button>' +
14111380
receiversBtn('spotactive1') +
14121381
audioInfoBtn('spotactive1') +
1413-
'<a id="inpsrc-spotify-refresh" class="btn spotify-renderer" href="javascript:refreshSpotmeta()"><i class="fa-regular fa-sharp fa-redo"></i></a>'
1382+
rendererRefreshBtn()
14141383
);
14151384

1416-
refreshSpotmeta();
1385+
refreshInpsrcMeta();
14171386
}
14181387
// Deezer Connect renderer
14191388
if (SESSION.json['deezactive'] == '1') {
@@ -1422,10 +1391,10 @@ function renderUI() {
14221391
'<button class="btn deezer-renderer disconnect-deezer" data-job="deezersvc"><i class="fa-regular fa-sharp fa-xmark"></i></button>' +
14231392
receiversBtn('deezactive1') +
14241393
audioInfoBtn('deezactive1') +
1425-
'<a id="inpsrc-deezer-refresh" class="btn deezer-renderer" href="javascript:refreshDeezmeta()"><i class="fa-regular fa-sharp fa-redo"></i></a>'
1394+
rendererRefreshBtn()
14261395
);
14271396

1428-
refreshDeezmeta();
1397+
refreshInpsrcMeta();
14291398
}
14301399
// Squeezelite renderer
14311400
if (SESSION.json['slactive'] == '1') {
@@ -1472,7 +1441,7 @@ function receiversBtn(rendererActive = '') {
14721441
if (SESSION.json['multiroom_tx'] == 'On') {
14731442
if (rendererActive == 'spotactive1') {
14741443
// data-cmd: multiroom_rx_modal (full modal), multiroom_rx_modal_limited (just the on/off checkbox)
1475-
var html = '<span class="context-menu"><a class="btn spotify-renderer" href="#notarget" data-cmd="multiroom_rx_modal"><i class="fa-regular fa-sharp fa-speakers"></i></a></span>';
1444+
var html = '<span class="context-menu"><a class="btn renderer-btn" href="#notarget" data-cmd="multiroom_rx_modal"><i class="fa-regular fa-sharp fa-speakers"></i></a></span>';
14761445
} else if (rendererActive == 'deezactive1') {
14771446
// data-cmd: multiroom_rx_modal (full modal), multiroom_rx_modal_limited (just the on/off checkbox)
14781447
var html = '<span class="context-menu"><a class="btn deezer-renderer" href="#notarget" data-cmd="multiroom_rx_modal"><i class="fa-regular fa-sharp fa-speakers"></i></a></span>';
@@ -1488,7 +1457,7 @@ function receiversBtn(rendererActive = '') {
14881457
// Audio info
14891458
function audioInfoBtn(rendererActive = '') {
14901459
if (rendererActive == 'spotactive1') {
1491-
var html = '<span><a class="btn spotify-renderer" href="javascript:audioInfoPlayback()"><i class="fa-regular fa-sharp fa-music"></i></a></span>';
1460+
var html = '<span><a class="btn renderer-btn" href="javascript:audioInfoPlayback()"><i class="fa-regular fa-sharp fa-music"></i></a></span>';
14921461
} else if (rendererActive == 'deezactive1') {
14931462
var html = '<span><a class="btn deezer-renderer" href="javascript:audioInfoPlayback()"><i class="fa-regular fa-sharp fa-music"></i></a></span>';
14941463
} else {
@@ -1498,6 +1467,16 @@ function audioInfoBtn(rendererActive = '') {
14981467
return html;
14991468
}
15001469

1470+
function rendererRefreshBtn() {
1471+
html = '<span id="renderer-refresh-btn"><a class="btn renderer-btn" href="javascript:refreshInpsrcMeta()"><i class="fa-regular fa-sharp fa-redo"></i></a></span';
1472+
return html;
1473+
}
1474+
1475+
function inpSrcMetaRefreshBtn() {
1476+
$('#renderer-refresh-btn').html('');
1477+
$('#inpsrc-metadata-refresh').html('<span><a class="btn renderer-btn" href="javascript:refreshInpsrcMeta()"><i class="fa-regular fa-sharp fa-redo"></i></a></span');
1478+
}
1479+
15011480
// Generate search url
15021481
function genSearchUrl (artist, title, album) {
15031482
// Search disabled by user

0 commit comments

Comments
 (0)