From abcc9c1007ae3110264d94c7f82e540bdfd907b0 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 14 Aug 2010 14:10:44 +0200 Subject: [PATCH] MPD: Improve seek impl and add seekid impl. Add tests which fails. --- docs/changes.rst | 1 + mopidy/frontends/mpd/protocol/playback.py | 6 +++++- tests/frontends/mpd/playback_test.py | 10 ++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 411d2547..a0a02ce7 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -46,6 +46,7 @@ greatly improved MPD client support. ``single`` without quotes to work better with BitMPC. - Fixed delete current playing track from playlist, which crashed several clients. + - Implement ``seek`` and ``seekid``. - Backends: diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index 58cd02fd..bfff275e 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -293,6 +293,8 @@ def seek(frontend, songpos, seconds): Seeks to the position ``TIME`` (in seconds) of entry ``SONGPOS`` in the playlist. """ + if frontend.backend.playback.current_playlist_position != songpos: + playpos(frontend, songpos) return frontend.backend.playback.seek(int(seconds) * 1000) @handle_pattern(r'^seekid "(?P\d+)" "(?P\d+)"$') @@ -304,7 +306,9 @@ def seekid(frontend, cpid, seconds): Seeks to the position ``TIME`` (in seconds) of song ``SONGID``. """ - raise MpdNotImplemented # TODO + if frontend.backend.playback.current_cpid != cpid: + playid(frontend, cpid) + return frontend.backend.playback.seek(int(seconds) * 1000) @handle_pattern(r'^setvol "(?P[-+]*\d+)"$') def setvol(frontend, volume): diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index 1cc3bc00..42525d90 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -271,12 +271,18 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_seek(self): + self.b.current_playlist.load([Track()]) + self.h.handle_request(u'seek "0"') result = self.h.handle_request(u'seek "0" "30"') - self.assert_(u'ACK [0@0] {} Not implemented' in result) + self.assert_(u'OK' in result) + self.assert_(self.b.playback.time_position > 30000) def test_seekid(self): + self.b.current_playlist.load([Track()]) result = self.h.handle_request(u'seekid "0" "30"') - self.assert_(u'ACK [0@0] {} Not implemented' in result) + self.assert_(u'OK' in result) + self.assert_(self.b.playback.time_position > 30000) + def test_stop(self): result = self.h.handle_request(u'stop')