From 8a9c868f77a9b1e2d80b4d0d6f70bbb0b62c5c84 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 13 Feb 2019 00:50:58 +0100 Subject: [PATCH] Bringing more consistency in music.mpd.js regardless of the backend --- platypush/backend/http/static/js/music.mpd.js | 10 +++++++--- platypush/backend/http/static/js/widgets/music.js | 12 +++++++++--- platypush/backend/music/mopidy.py | 7 ++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/platypush/backend/http/static/js/music.mpd.js b/platypush/backend/http/static/js/music.mpd.js index e8271acd0..adfa96ed6 100644 --- a/platypush/backend/http/static/js/music.mpd.js +++ b/platypush/backend/http/static/js/music.mpd.js @@ -4,8 +4,8 @@ $(document).ready(function() { curPath = [], curTrackUpdateHandler, curTrackElapsed = { - timestamp: null, - elapsed: null, + timestamp: undefined, + elapsed: undefined, }, $musicSearchForm = $('#music-search-form'), @@ -125,6 +125,10 @@ $(document).ready(function() { $('#seek-time-length').text(length ? timeToStr(length) : '-:--'); seekInterval = setInterval(function() { + if (curTrackElapsed.elapsed === undefined) { + return; + } + var length = parseInt($trackSeeker.attr('max')); var value = parseInt((new Date().getTime() - curTrackElapsed.timestamp)/1000) + curTrackElapsed.elapsed; @@ -169,7 +173,7 @@ $(document).ready(function() { var updatePlayingTrack = function(track) { return function() { var $curTrack = $playlistContent.find('.playlist-track').filter( - function() { return $(this).data('pos') == track.pos }); + function() { return $(this).data('file') === track.file }); if ($curTrack.length === 0) { return; diff --git a/platypush/backend/http/static/js/widgets/music.js b/platypush/backend/http/static/js/widgets/music.js index ab1465012..e74e08c64 100644 --- a/platypush/backend/http/static/js/widgets/music.js +++ b/platypush/backend/http/static/js/widgets/music.js @@ -105,20 +105,26 @@ $(document).ready(function() { }; var refreshStatus = function(status) { + if (!status) { + return; + } + if ('state' in status) { setState(state=status.state); } if ('elapsed' in status) { setTrackElapsed(status.elapsed); - } - - if ('position' in status) { + } else if ('position' in status) { setTrackElapsed(status.position); } }; var refreshTrack = function(track) { + if (!track) { + return; + } + if ('time' in track) { setTrackTime(track.time); } diff --git a/platypush/backend/music/mopidy.py b/platypush/backend/music/mopidy.py index 6d32dfa30..252e89333 100644 --- a/platypush/backend/music/mopidy.py +++ b/platypush/backend/music/mopidy.py @@ -143,6 +143,10 @@ class MusicMopidyBackend(Backend): track = self._parse_track(track) if not track: return + + status['state'] = 'play' + status['position'] = 0.0 + status['time'] = track.get('time') self.bus.post(NewPlayingTrackEvent(status=status, track=track)) elif event == 'stream_title_changed': m = re.match('^\s*(.+?)\s+-\s+(.*)\s*$', msg.get('title', '')) @@ -151,7 +155,8 @@ class MusicMopidyBackend(Backend): track['artist'] = m.group(1) track['title'] = m.group(2) - track['position'] = 0.0 + status['state'] = 'play' + status['position'] = 0.0 self.bus.post(NewPlayingTrackEvent(status=status, track=track)) elif event == 'volume_changed': status['volume'] = msg.get('volume')