bpd: skipping backwards through zero keeps playing

Previously issuing the 'previous' command when at position 0 on the
playlist would cause bpd to stop playing. MPD instead just restarts the
currently playing song instead, so we now match this behaviour.
This commit is contained in:
Carl Suster 2019-04-01 17:51:21 +11:00
parent a4fe6875a1
commit 12e49b3c88
2 changed files with 20 additions and 4 deletions

View file

@ -554,9 +554,8 @@ class BaseServer(object):
"""Step back to the last song."""
self.current_index = self._prev_idx()
if self.current_index < 0:
return self.cmd_stop(conn)
else:
return self.cmd_play(conn)
self.current_index = 0
return self.cmd_play(conn)
def cmd_pause(self, conn, state=None):
"""Set the pause state playback."""

View file

@ -519,7 +519,7 @@ class BPDPlaybackTest(BPDTestHelper):
class BPDControlTest(BPDTestHelper):
test_implements_control = implements({
'pause', 'playid', 'previous', 'seek',
'pause', 'playid', 'seek',
'seekid', 'seekcur', 'stop',
}, expectedFailure=True)
@ -552,6 +552,23 @@ class BPDControlTest(BPDTestHelper):
self.assertEqual('2', responses[3].data['Id'])
self.assertEqual('stop', responses[5].data['state'])
def test_cmd_previous(self):
with self.run_bpd() as client:
self._bpd_add(client, self.item1, self.item2)
responses = client.send_commands(
('play', '1'),
('currentsong',),
('previous',),
('currentsong',),
('previous',),
('status',),
('currentsong',))
self._assert_ok(*responses)
self.assertEqual('2', responses[1].data['Id'])
self.assertEqual('1', responses[3].data['Id'])
self.assertEqual('play', responses[5].data['state'])
self.assertEqual('1', responses[6].data['Id'])
class BPDQueueTest(BPDTestHelper):
test_implements_queue = implements({