Test and implement mpris.CanPlay property
This commit is contained in:
parent
97111d710f
commit
4013a2ec9a
@ -151,8 +151,7 @@ class MprisObject(dbus.service.Object):
|
|||||||
'CanGoNext': (False, None),
|
'CanGoNext': (False, None),
|
||||||
# TODO True if CanControl and backend.playback.track_at_previous
|
# TODO True if CanControl and backend.playback.track_at_previous
|
||||||
'CanGoPrevious': (False, None),
|
'CanGoPrevious': (False, None),
|
||||||
# TODO True if CanControl and backend.playback.current_track
|
'CanPlay': (self.get_CanPlay, None),
|
||||||
'CanPlay': (False, None),
|
|
||||||
'CanPause': (self.get_CanPause, None),
|
'CanPause': (self.get_CanPause, None),
|
||||||
'CanSeek': (self.get_CanSeek, None),
|
'CanSeek': (self.get_CanSeek, None),
|
||||||
'CanControl': (self.get_CanControl, None),
|
'CanControl': (self.get_CanControl, None),
|
||||||
@ -408,6 +407,12 @@ class MprisObject(dbus.service.Object):
|
|||||||
def get_Position(self):
|
def get_Position(self):
|
||||||
return self.backend.playback.time_position.get() * 1000
|
return self.backend.playback.time_position.get() * 1000
|
||||||
|
|
||||||
|
def get_CanPlay(self):
|
||||||
|
if not self.get_CanControl():
|
||||||
|
return False
|
||||||
|
return (self.backend.playback.current_track.get() is not None
|
||||||
|
or self.backend.playback.track_at_next.get() is not None)
|
||||||
|
|
||||||
def get_CanPause(self):
|
def get_CanPause(self):
|
||||||
if not self.get_CanControl():
|
if not self.get_CanControl():
|
||||||
return False
|
return False
|
||||||
|
|||||||
@ -177,6 +177,25 @@ class PlayerInterfaceTest(unittest.TestCase):
|
|||||||
result = self.mpris.Get(mpris.PLAYER_IFACE, 'MaximumRate')
|
result = self.mpris.Get(mpris.PLAYER_IFACE, 'MaximumRate')
|
||||||
self.assert_(result >= 1.0)
|
self.assert_(result >= 1.0)
|
||||||
|
|
||||||
|
def test_can_play_is_true_if_can_control_and_current_track(self):
|
||||||
|
self.mpris.get_CanControl = lambda *_: True
|
||||||
|
self.backend.current_playlist.append([Track(uri='a')])
|
||||||
|
self.backend.playback.play()
|
||||||
|
self.assertTrue(self.backend.playback.current_track.get())
|
||||||
|
result = self.mpris.Get(mpris.PLAYER_IFACE, 'CanPlay')
|
||||||
|
self.assertTrue(result)
|
||||||
|
|
||||||
|
def test_can_play_is_false_if_no_current_track(self):
|
||||||
|
self.mpris.get_CanControl = lambda *_: True
|
||||||
|
self.assertFalse(self.backend.playback.current_track.get())
|
||||||
|
result = self.mpris.Get(mpris.PLAYER_IFACE, 'CanPlay')
|
||||||
|
self.assertFalse(result)
|
||||||
|
|
||||||
|
def test_can_play_if_false_if_can_control_is_false(self):
|
||||||
|
self.mpris.get_CanControl = lambda *_: False
|
||||||
|
result = self.mpris.Get(mpris.PLAYER_IFACE, 'CanPlay')
|
||||||
|
self.assertFalse(result)
|
||||||
|
|
||||||
def test_can_pause_is_true_if_can_control_and_track_can_be_paused(self):
|
def test_can_pause_is_true_if_can_control_and_track_can_be_paused(self):
|
||||||
self.mpris.get_CanControl = lambda *_: True
|
self.mpris.get_CanControl = lambda *_: True
|
||||||
result = self.mpris.Get(mpris.PLAYER_IFACE, 'CanPause')
|
result = self.mpris.Get(mpris.PLAYER_IFACE, 'CanPause')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user