From d1449bcb6fe28044a0a2ddf79c746f9dc09f2af0 Mon Sep 17 00:00:00 2001 From: Nantas Nardelli Date: Sun, 24 Jul 2016 20:30:48 +0100 Subject: [PATCH 1/3] Properly get track position before change events In particular, this allows to send the right information when: 1. the track finishes and switches to the next one in the list; 2. user presses next / previous The cases of EOS and stop event were already handled properly. Note: we only have GStreamer's `about-to-finish` event to deal with the end of a track, which usually happens a few seconds before the end of the track. We set the position to the length of the track, which is not overridden unless the user generates a relevant callback. --- mopidy/core/playback.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mopidy/core/playback.py b/mopidy/core/playback.py index da505b22..ab0bee5b 100644 --- a/mopidy/core/playback.py +++ b/mopidy/core/playback.py @@ -251,6 +251,10 @@ class PlaybackController(object): if self._state == PlaybackState.STOPPED: return + # Unless overridden by other calls (e.g. next / previous / stop) this + # will be the last position recorded until the track gets reassigned. + self._last_position = self._current_tl_track.track.length + pending = self.core.tracklist.eot_track(self._current_tl_track) # avoid endless loop if 'repeat' is 'true' and no track is playable # * 2 -> second run to get all playable track in a shuffled playlist @@ -394,6 +398,10 @@ class PlaybackController(object): if not backend: return False + # This must happen before prepare_change gets called, otherwise the + # backend flushes the information of the track. + self._last_position = self.get_time_position() + # TODO: Wrap backend call in error handling. backend.playback.prepare_change() From 500ff70b87b11d167c72071fb889fbf56e0dc359 Mon Sep 17 00:00:00 2001 From: Nantas Nardelli Date: Sun, 24 Jul 2016 21:52:15 +0100 Subject: [PATCH 2/3] Add changelog entry for #1534, and fix #1523 typo --- docs/changelog.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 1411d347..067adc46 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -42,7 +42,12 @@ Bug fix release. remains unimplemented. (PR: :issue:`1520`) - MPD: Add ``nextsong`` and ``nextsongid`` to the response of MPD ``status`` command. - (Fixes: :issue:`1133` :issue:`1516`, PR: :issue:`1523`) + (Fixes: :issue:`1133`, :issue:`1516`, PR: :issue:`1523`) + +- Core: Correctly record the last position of a track when switching to another + one. Particularly relevant for `mopidy-scrobbler` users, as before it was + essentially unusable. (Fixes: :issue:`1456`, PR: :issue:`1534`) + v2.0.0 (2016-02-15) =================== From 6e603a183b3b492a43c91d0833afc9e5f3a2f6ab Mon Sep 17 00:00:00 2001 From: Nantas Nardelli Date: Sun, 24 Jul 2016 22:26:59 +0100 Subject: [PATCH 3/3] Add TODO about checking length of track when null --- mopidy/core/playback.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mopidy/core/playback.py b/mopidy/core/playback.py index ab0bee5b..0106abf2 100644 --- a/mopidy/core/playback.py +++ b/mopidy/core/playback.py @@ -253,6 +253,8 @@ class PlaybackController(object): # Unless overridden by other calls (e.g. next / previous / stop) this # will be the last position recorded until the track gets reassigned. + # TODO: Check if case when track.length isn't populated needs to be + # handled. self._last_position = self._current_tl_track.track.length pending = self.core.tracklist.eot_track(self._current_tl_track)