forked from platypush/platypush
More compatibility between TCP-based mpd and websocket-based mopidy backends when it comes to how the track time is reported
This commit is contained in:
parent
77a76370a5
commit
71c6ba2d34
2 changed files with 33 additions and 12 deletions
|
@ -45,28 +45,45 @@ $(document).ready(function() {
|
|||
var $repeatBtn = $playbackControls.find('[data-action=repeat]');
|
||||
var elapsed; var length;
|
||||
|
||||
var timeToStr = (time) => {
|
||||
return parseInt(parseInt(time)/60) + ':'
|
||||
+ (parseInt(time)%60 < 10 ? '0' : '') + (parseInt(time)%60);
|
||||
};
|
||||
|
||||
if (status) {
|
||||
if (seekInterval) {
|
||||
clearInterval(seekInterval);
|
||||
}
|
||||
|
||||
if ('time' in status) {
|
||||
var time = status.time.split(':');
|
||||
elapsed = parseInt(parseInt(time[0])/60) + ':'
|
||||
+ (parseInt(time[0])%60 < 10 ? '0' : '') + (parseInt(time[0])%60);
|
||||
var time; var elapsed;
|
||||
|
||||
if (time.length > 1) {
|
||||
length = parseInt(parseInt(time[1])/60) + ':'
|
||||
+ (parseInt(time[1])%60 < 10 ? '0' : '') + (parseInt(time[1])%60);
|
||||
if (typeof status.time === 'string' && status.time.indexOf(':') > -1) {
|
||||
// backend.music.mpd time format: "elapsed:total"
|
||||
[elapsed, time] = status.time.split(':');
|
||||
elapsed = parseInt(elapsed);
|
||||
time = parseInt(time);
|
||||
} else {
|
||||
// backend.music.mopidy time format: integer with elapsed seconds
|
||||
time = parseInt(status.time);
|
||||
}
|
||||
|
||||
$trackSeeker.val(parseInt(time[0]));
|
||||
$trackSeeker.attr('max', parseInt(time[1]));
|
||||
if (time) {
|
||||
$trackSeeker.val(time);
|
||||
}
|
||||
|
||||
if (elapsed) {
|
||||
$trackSeeker.attr('max', elapsed);
|
||||
curTrackElapsed = {
|
||||
timestamp: new Date().getTime(),
|
||||
elapsed: parseInt(time[0]),
|
||||
'timestamp': new Date().getTime(),
|
||||
'elapsed': elapsed,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ('position' in status) {
|
||||
$trackSeeker.val(parseInt(status.position));
|
||||
}
|
||||
|
||||
if ('state' in status) {
|
||||
switch (status.state.toLowerCase()) {
|
||||
|
@ -187,6 +204,7 @@ $(document).ready(function() {
|
|||
case 'platypush.message.event.music.MusicStopEvent':
|
||||
case 'platypush.message.event.music.MusicPlayEvent':
|
||||
case 'platypush.message.event.music.MusicPauseEvent':
|
||||
case 'platypush.message.event.music.SeekChangeEvent':
|
||||
updateControls(status=event.args.status, track=event.args.track);
|
||||
break;
|
||||
|
||||
|
|
|
@ -75,6 +75,9 @@ class MusicMopidyBackend(Backend):
|
|||
if pos is not None:
|
||||
conv_track['pos'] = pos
|
||||
|
||||
if '__model__' in conv_track:
|
||||
del conv_track['__model__']
|
||||
|
||||
return conv_track
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue