state might not always be provided in a music event
This commit is contained in:
parent
18d2c51b4e
commit
97855b1535
1 changed files with 42 additions and 40 deletions
|
@ -68,53 +68,55 @@ $(document).ready(function() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (status.state.toLowerCase()) {
|
if ('state' in status) {
|
||||||
case 'stop':
|
switch (status.state.toLowerCase()) {
|
||||||
$playbackControls.find('button[data-action=pause]').hide();
|
case 'stop':
|
||||||
$playbackControls.find('button[data-action=play]').show();
|
$playbackControls.find('button[data-action=pause]').hide();
|
||||||
$curTrack.find('.artist').hide();
|
$playbackControls.find('button[data-action=play]').show();
|
||||||
$curTrack.find('.track').hide();
|
$curTrack.find('.artist').hide();
|
||||||
$curTrack.find('.no-track').show();
|
$curTrack.find('.track').hide();
|
||||||
|
$curTrack.find('.no-track').show();
|
||||||
|
|
||||||
$trackSeeker.prop('disabled', true);
|
$trackSeeker.prop('disabled', true);
|
||||||
$('.seek-time').text('-:--');
|
$('.seek-time').text('-:--');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'pause':
|
case 'pause':
|
||||||
$playbackControls.find('button[data-action=pause]').hide();
|
$playbackControls.find('button[data-action=pause]').hide();
|
||||||
$playbackControls.find('button[data-action=play]').show();
|
$playbackControls.find('button[data-action=play]').show();
|
||||||
$curTrack.find('.artist').show();
|
$curTrack.find('.artist').show();
|
||||||
$curTrack.find('.track').show();
|
$curTrack.find('.track').show();
|
||||||
$curTrack.find('.no-track').hide();
|
$curTrack.find('.no-track').hide();
|
||||||
|
|
||||||
$trackSeeker.prop('disabled', false);
|
$trackSeeker.prop('disabled', false);
|
||||||
$('#seek-time-elapsed').text(elapsed ? elapsed : '-:--');
|
$('#seek-time-elapsed').text(elapsed ? elapsed : '-:--');
|
||||||
$('#seek-time-length').text(length ? length : '-:--');
|
$('#seek-time-length').text(length ? length : '-:--');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'play':
|
case 'play':
|
||||||
$playbackControls.find('button[data-action=pause]').show();
|
$playbackControls.find('button[data-action=pause]').show();
|
||||||
$playbackControls.find('button[data-action=play]').hide();
|
$playbackControls.find('button[data-action=play]').hide();
|
||||||
$curTrack.find('.artist').show();
|
$curTrack.find('.artist').show();
|
||||||
$curTrack.find('.track').show();
|
$curTrack.find('.track').show();
|
||||||
$curTrack.find('.no-track').hide();
|
$curTrack.find('.no-track').hide();
|
||||||
|
|
||||||
$trackSeeker.prop('disabled', false);
|
$trackSeeker.prop('disabled', false);
|
||||||
$('#seek-time-elapsed').text(elapsed ? elapsed : '-:--');
|
$('#seek-time-elapsed').text(elapsed ? elapsed : '-:--');
|
||||||
$('#seek-time-length').text(length ? length : '-:--');
|
$('#seek-time-length').text(length ? length : '-:--');
|
||||||
|
|
||||||
seekInterval = setInterval(function() {
|
seekInterval = setInterval(function() {
|
||||||
var length = parseInt($trackSeeker.attr('max'));
|
var length = parseInt($trackSeeker.attr('max'));
|
||||||
var value = parseInt((new Date().getTime() - curTrackElapsed.timestamp)/1000)
|
var value = parseInt((new Date().getTime() - curTrackElapsed.timestamp)/1000)
|
||||||
+ curTrackElapsed.elapsed;
|
+ curTrackElapsed.elapsed;
|
||||||
|
|
||||||
if (value < length) {
|
if (value < length) {
|
||||||
$trackSeeker.val(value);
|
$trackSeeker.val(value);
|
||||||
elapsed = parseInt(value/60) + ':' + (value%60 < 10 ? '0' : '') + (value%60);
|
elapsed = parseInt(value/60) + ':' + (value%60 < 10 ? '0' : '') + (value%60);
|
||||||
$('#seek-time-elapsed').text(elapsed);
|
$('#seek-time-elapsed').text(elapsed);
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('volume' in status) {
|
if ('volume' in status) {
|
||||||
|
|
Loading…
Reference in a new issue