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:
Fabio Manganiello 2019-02-12 23:48:18 +01:00
parent 77a76370a5
commit 71c6ba2d34
2 changed files with 33 additions and 12 deletions

View file

@ -45,27 +45,44 @@ $(document).ready(function() {
var $repeatBtn = $playbackControls.find('[data-action=repeat]'); var $repeatBtn = $playbackControls.find('[data-action=repeat]');
var elapsed; var length; var elapsed; var length;
var timeToStr = (time) => {
return parseInt(parseInt(time)/60) + ':'
+ (parseInt(time)%60 < 10 ? '0' : '') + (parseInt(time)%60);
};
if (status) { if (status) {
if (seekInterval) { if (seekInterval) {
clearInterval(seekInterval); clearInterval(seekInterval);
} }
if ('time' in status) { if ('time' in status) {
var time = status.time.split(':'); var time; var elapsed;
elapsed = parseInt(parseInt(time[0])/60) + ':'
+ (parseInt(time[0])%60 < 10 ? '0' : '') + (parseInt(time[0])%60);
if (time.length > 1) { if (typeof status.time === 'string' && status.time.indexOf(':') > -1) {
length = parseInt(parseInt(time[1])/60) + ':' // backend.music.mpd time format: "elapsed:total"
+ (parseInt(time[1])%60 < 10 ? '0' : '') + (parseInt(time[1])%60); [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])); if (time) {
$trackSeeker.attr('max', parseInt(time[1])); $trackSeeker.val(time);
curTrackElapsed = { }
timestamp: new Date().getTime(),
elapsed: parseInt(time[0]), if (elapsed) {
}; $trackSeeker.attr('max', elapsed);
curTrackElapsed = {
'timestamp': new Date().getTime(),
'elapsed': elapsed,
};
}
}
if ('position' in status) {
$trackSeeker.val(parseInt(status.position));
} }
if ('state' in status) { if ('state' in status) {
@ -187,6 +204,7 @@ $(document).ready(function() {
case 'platypush.message.event.music.MusicStopEvent': case 'platypush.message.event.music.MusicStopEvent':
case 'platypush.message.event.music.MusicPlayEvent': case 'platypush.message.event.music.MusicPlayEvent':
case 'platypush.message.event.music.MusicPauseEvent': case 'platypush.message.event.music.MusicPauseEvent':
case 'platypush.message.event.music.SeekChangeEvent':
updateControls(status=event.args.status, track=event.args.track); updateControls(status=event.args.status, track=event.args.track);
break; break;

View file

@ -75,6 +75,9 @@ class MusicMopidyBackend(Backend):
if pos is not None: if pos is not None:
conv_track['pos'] = pos conv_track['pos'] = pos
if '__model__' in conv_track:
del conv_track['__model__']
return conv_track return conv_track