From 15c992e06a605078c9fe245551af19c1f6ac429e Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 12 Feb 2011 01:45:36 +0100 Subject: [PATCH] Add 'play -1' support, which fixes resume in MPoD --- docs/changes.rst | 2 ++ mopidy/frontends/mpd/protocol/playback.py | 23 ++++++++++++++++------- tests/frontends/mpd/playback_test.py | 12 ++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index b1e8e608..63c0c22b 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -19,6 +19,8 @@ No description yet. commands. This makes media library browsing in ncmpcpp work, though very slow due to all the meta data requests to Spotify. + - Add support for ``play "-1"``, which fixes resume in MPoD. + - Settings: - Fix crash on ``--list-settings`` on clean installation. Thanks to Martins diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index 19922bc3..3f0421dc 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -132,10 +132,13 @@ def playid(frontend, cpid): Begins playing the playlist at song ``SONGID``. - *GMPC:* + *Clarifications:* - - issues ``playid "-1"`` after playlist replacement to start playback - at the first track. + - ``playid "-1"`` when paused resumes playback. + - ``playid "-1"`` when stopped with a current track starts playback at the + current track. + - ``playid "-1"`` when stopped without a current track, e.g. after playlist + replacement, starts playback at the first track. """ cpid = int(cpid) paused = (frontend.backend.playback.state == @@ -161,17 +164,23 @@ def playpos(frontend, songpos): Begins playing the playlist at song number ``SONGPOS``. - *Many clients:* + *Clarifications:* - - issue ``play "-1"`` after playlist replacement to start the current - track. If the current track is not set, start playback at the first - track. + - ``playid "-1"`` when paused resumes playback. + - ``playid "-1"`` when stopped with a current track starts playback at the + current track. + - ``playid "-1"`` when stopped without a current track, e.g. after playlist + replacement, starts playback at the first track. *BitMPC:* - issues ``play 6`` without quotes around the argument. """ songpos = int(songpos) + paused = (frontend.backend.playback.state == + frontend.backend.playback.PAUSED) + if songpos == -1 and paused: + return frontend.backend.playback.resume() try: if songpos == -1: cp_track = _get_cp_track_for_play_minus_one(frontend) diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index 64e9f882..face0318 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -257,6 +257,18 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assertEqual(self.b.playback.STOPPED, self.b.playback.state) self.assertEqual(self.b.playback.current_track, None) + def test_play_minus_one_resumes_if_paused(self): + self.b.current_playlist.append([Track(length=40000)]) + self.b.playback.seek(30000) + self.assert_(self.b.playback.time_position >= 30000) + self.assertEquals(self.b.playback.PLAYING, self.b.playback.state) + self.b.playback.pause() + self.assertEquals(self.b.playback.PAUSED, self.b.playback.state) + result = self.h.handle_request(u'play "-1"') + self.assert_(u'OK' in result) + self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) + self.assert_(self.b.playback.time_position >= 30000) + def test_playid(self): self.b.current_playlist.append([Track()]) result = self.h.handle_request(u'playid "0"')