Use seconds for seek, make TrackId optional

This commit is contained in:
badaix 2021-06-24 14:39:04 +02:00
parent 0853c7c701
commit 880ed00604
3 changed files with 15 additions and 15 deletions

View file

@ -389,14 +389,14 @@ class MPDWrapper(object):
elif command == 'Stop': elif command == 'Stop':
self.stop() self.stop()
elif command == 'SetPosition': elif command == 'SetPosition':
trackid = params['TrackId'] position = float(params['Position'])
trackid = trackid.rsplit('/', 1)[1] if 'TrackId' in params:
position = params['Position'] trackid = params['TrackId'].rsplit('/', 1)[1]
position = int(position) / 1000000 self.seekid(int(trackid), position)
self.seekid(int(trackid), position) else:
self.seekcur(position)
elif command == 'Seek': elif command == 'Seek':
offset = params['Offset'] offset = float(params['Offset'])
offset = int(offset) / 1000000
strOffset = str(offset) strOffset = str(offset)
if offset >= 0: if offset >= 0:
strOffset = "+" + strOffset strOffset = "+" + strOffset

View file

@ -321,7 +321,7 @@ class SnapcastWrapper(object):
if key in tag_mapping: if key in tag_mapping:
try: try:
self._metadata[tag_mapping[key][0] self._metadata[tag_mapping[key][0]
] = tag_mapping[key][1](value) ] = tag_mapping[key][1](value)
except KeyError: except KeyError:
logger.warning(f'tag "{key}" not supported') logger.warning(f'tag "{key}" not supported')
except (ValueError, TypeError): except (ValueError, TypeError):
@ -329,13 +329,13 @@ class SnapcastWrapper(object):
f"Can't cast value {value} to {tag_mapping[key][1]}") f"Can't cast value {value} to {tag_mapping[key][1]}")
if not 'mpris:artUrl' in self._metadata: if not 'mpris:artUrl' in self._metadata:
self._metadata['mpris:artUrl'] = f'http://{self._params["host"]}:{self._params["port"]}/launcher-icon.png' self._metadata['mpris:artUrl'] = f'http://{self._params["host"]}:{self._params["port"]}/snapcast-512.png'
logger.info(f'mpris meta: {self._metadata}') logger.info(f'mpris meta: {self._metadata}')
self.notify_about_track(self._metadata) self.notify_about_track(self._metadata)
new_meta = self._dbus_service.update_property('org.mpris.MediaPlayer2.Player', new_meta = self._dbus_service.update_property('org.mpris.MediaPlayer2.Player',
'Metadata') 'Metadata')
logger.info(f'new meta {new_meta}') logger.info(f'new meta {new_meta}')
except Exception as e: except Exception as e:
logger.error(f'Error in update_metadata: {str(e)}') logger.error(f'Error in update_metadata: {str(e)}')
@ -926,7 +926,7 @@ class MPRISInterface(dbus.service.Object):
@ dbus.service.method(__player_interface, in_signature='x', out_signature='') @ dbus.service.method(__player_interface, in_signature='x', out_signature='')
def Seek(self, offset): def Seek(self, offset):
logger.debug(f'Seek {offset}') logger.debug(f'Seek {offset}')
snapcast_wrapper.control("Seek", {"Offset": offset}) snapcast_wrapper.control("Seek", {"Offset": float(offset) / 1000000})
# status = mpd_wrapper.status() # status = mpd_wrapper.status()
# current, end = status['time'].split(':') # current, end = status['time'].split(':')
# current = int(current) # current = int(current)
@ -944,7 +944,7 @@ class MPRISInterface(dbus.service.Object):
def SetPosition(self, trackid, position): def SetPosition(self, trackid, position):
logger.debug(f'SetPosition TrackId: {trackid}, Position: {position}') logger.debug(f'SetPosition TrackId: {trackid}, Position: {position}')
snapcast_wrapper.control( snapcast_wrapper.control(
"SetPosition", {"TrackId": trackid, "Position": position}) "SetPosition", {"TrackId": trackid, "Position": float(position) / 1000000})
self.Seeked(position) self.Seeked(position)
# song = mpd_wrapper.last_currentsong() # song = mpd_wrapper.last_currentsong()

View file

@ -387,8 +387,8 @@ void PcmStream::control(const jsonrpcpp::Request& request, const StreamControl::
std::string command = request.params().get("command"); std::string command = request.params().get("command");
if (command == "SetPosition") if (command == "SetPosition")
{ {
if (!request.params().has("params") || !request.params().get("params").contains("Position") || !request.params().get("params").contains("TrackId")) if (!request.params().has("params") || !request.params().get("params").contains("Position"))
throw SnapException("SetPosition requires parameters 'Position' and 'TrackId'"); throw SnapException("SetPosition requires parameters 'Position' and optionally 'TrackId'");
if (!properties_.can_seek) if (!properties_.can_seek)
throw SnapException("CanSeek is false"); throw SnapException("CanSeek is false");
} }