From 71c6ba2d34e7fb1f5a65009ee6169f0dd8f93677 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 12 Feb 2019 23:48:18 +0100 Subject: [PATCH] More compatibility between TCP-based mpd and websocket-based mopidy backends when it comes to how the track time is reported --- platypush/backend/http/static/js/music.mpd.js | 42 +++++++++++++------ platypush/backend/music/mopidy.py | 3 ++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/platypush/backend/http/static/js/music.mpd.js b/platypush/backend/http/static/js/music.mpd.js index 7366f5181..3142f6677 100644 --- a/platypush/backend/http/static/js/music.mpd.js +++ b/platypush/backend/http/static/js/music.mpd.js @@ -45,27 +45,44 @@ $(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])); - curTrackElapsed = { - timestamp: new Date().getTime(), - elapsed: parseInt(time[0]), - }; + if (time) { + $trackSeeker.val(time); + } + + 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) { @@ -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; diff --git a/platypush/backend/music/mopidy.py b/platypush/backend/music/mopidy.py index 17df76ba7..7d42ed076 100644 --- a/platypush/backend/music/mopidy.py +++ b/platypush/backend/music/mopidy.py @@ -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