diff --git a/platypush/backend/http/static/js/music.mpd.js b/platypush/backend/http/static/js/music.mpd.js index e8271acd08..adfa96ed67 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 ab14650120..e74e08c64d 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 6d32dfa301..252e893330 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')