From: Mike Frysinger Date: Tue, 3 Sep 2013 18:10:56 +0000 (-0400) Subject: controls: fix display of volume/position when values are unknown X-Git-Tag: v3.1~1 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=999ae517c6544938a712422c9dd3cc210a319ebd;p=chrome-ext%2Fmusic-player-client.git controls: fix display of volume/position when values are unknown Like when mpd is stopped and you connect for the first time. --- diff --git a/main.js b/main.js index 5b05cee..208f996 100644 --- a/main.js +++ b/main.js @@ -356,20 +356,25 @@ function update_ui(state, cmd) { }); /* Update the status tab. */ - var time; - if ('time' in state) + var time, percent; + if ('time' in state) { // When stopped, there is no time field at all. time = state.time.split(':'); - else + percent = Math.floor((0.0 + time[0]) * 100 / (0.0 + time[1])); + } else { time = [0, 0]; + percent = 0; + } ui_mpc_seekcur.max = time[1]; ui_mpc_seekcur.value = time[0]; - percent = Math.floor((0.0 + time[0]) * 100 / (0.0 + time[1])); ui_mpc_seekcur.title = 'seekcur (' + percent + '%)'; ui_mpc_currtime.innerText = [pretty_time(time[0]), pretty_time(time[1]), percent + '%'].join(' / '); - ui_mpc_setvol.value = state.volume; - ui_mpc_setvol.title = 'setvol (' + state.volume + '%)'; + ui_mpc_setvol.title = 'setvol'; + if ('volume' in state) { + ui_mpc_setvol.value = state.volume; + ui_mpc_setvol.title += ' (' + state.volume + '%)'; + } [ 'consume', 'random', 'repeat', 'single',