Update SetPosition to support real track IDs instead of URIs
This commit is contained in:
parent
190faf745a
commit
e5725bb26b
@ -177,6 +177,12 @@ class MprisObject(dbus.service.Object):
|
|||||||
self._mixer = mixer_refs[0].proxy()
|
self._mixer = mixer_refs[0].proxy()
|
||||||
return self._mixer
|
return self._mixer
|
||||||
|
|
||||||
|
def _get_track_id(self, cp_track):
|
||||||
|
return '/com/mopidy/track/%d' % cp_track.cpid
|
||||||
|
|
||||||
|
def _get_cpid(self, track_id):
|
||||||
|
assert track_id.startswith('/com/mopidy/track/')
|
||||||
|
return track_id.split('/')[-1]
|
||||||
|
|
||||||
### Properties interface
|
### Properties interface
|
||||||
|
|
||||||
@ -314,15 +320,14 @@ class MprisObject(dbus.service.Object):
|
|||||||
logger.debug(u'%s.SetPosition not allowed', PLAYER_IFACE)
|
logger.debug(u'%s.SetPosition not allowed', PLAYER_IFACE)
|
||||||
return
|
return
|
||||||
position = position // 1000
|
position = position // 1000
|
||||||
current_track = self.backend.playback.current_track.get()
|
current_cp_track = self.backend.playback.current_cp_track.get()
|
||||||
# TODO Currently the ID is assumed to be the URI of the track. This
|
if current_cp_track is None:
|
||||||
# should be changed to a D-Bus object ID than can be mapped to the CPID
|
return
|
||||||
# and URI of the track.
|
if track_id != self._get_track_id(current_cp_track):
|
||||||
if current_track and current_track.uri != track_id:
|
|
||||||
return
|
return
|
||||||
if position < 0:
|
if position < 0:
|
||||||
return
|
return
|
||||||
if current_track and current_track.length < position:
|
if current_cp_track.track.length < position:
|
||||||
return
|
return
|
||||||
self.backend.playback.seek(position)
|
self.backend.playback.seek(position)
|
||||||
|
|
||||||
@ -414,7 +419,7 @@ class MprisObject(dbus.service.Object):
|
|||||||
return {'mpris:trackid': ''}
|
return {'mpris:trackid': ''}
|
||||||
else:
|
else:
|
||||||
(cpid, track) = current_cp_track
|
(cpid, track) = current_cp_track
|
||||||
metadata = {'mpris:trackid': '/com/mopidy/track/%d' % cpid}
|
metadata = {'mpris:trackid': self._get_track_id(current_cp_track)}
|
||||||
if track.length:
|
if track.length:
|
||||||
metadata['mpris:length'] = track.length * 1000
|
metadata['mpris:length'] = track.length * 1000
|
||||||
if track.uri:
|
if track.uri:
|
||||||
|
|||||||
@ -675,7 +675,7 @@ class PlayerInterfaceTest(unittest.TestCase):
|
|||||||
self.assert_(before_set_position <= 5000)
|
self.assert_(before_set_position <= 5000)
|
||||||
self.assertEquals(self.backend.playback.state.get(), PLAYING)
|
self.assertEquals(self.backend.playback.state.get(), PLAYING)
|
||||||
|
|
||||||
track_id = 'a'
|
track_id = '/com/mopidy/track/0'
|
||||||
|
|
||||||
position_to_set_in_milliseconds = 20000
|
position_to_set_in_milliseconds = 20000
|
||||||
position_to_set_in_microseconds = position_to_set_in_milliseconds * 1000
|
position_to_set_in_microseconds = position_to_set_in_milliseconds * 1000
|
||||||
@ -698,7 +698,7 @@ class PlayerInterfaceTest(unittest.TestCase):
|
|||||||
self.assertEquals(self.backend.playback.state.get(), PLAYING)
|
self.assertEquals(self.backend.playback.state.get(), PLAYING)
|
||||||
self.assertEquals(self.backend.playback.current_track.get().uri, 'a')
|
self.assertEquals(self.backend.playback.current_track.get().uri, 'a')
|
||||||
|
|
||||||
track_id = 'a'
|
track_id = '/com/mopidy/track/0'
|
||||||
|
|
||||||
position_to_set_in_milliseconds = -1000
|
position_to_set_in_milliseconds = -1000
|
||||||
position_to_set_in_microseconds = position_to_set_in_milliseconds * 1000
|
position_to_set_in_microseconds = position_to_set_in_milliseconds * 1000
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user