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':
self.stop()
elif command == 'SetPosition':
trackid = params['TrackId']
trackid = trackid.rsplit('/', 1)[1]
position = params['Position']
position = int(position) / 1000000
position = float(params['Position'])
if 'TrackId' in params:
trackid = params['TrackId'].rsplit('/', 1)[1]
self.seekid(int(trackid), position)
else:
self.seekcur(position)
elif command == 'Seek':
offset = params['Offset']
offset = int(offset) / 1000000
offset = float(params['Offset'])
strOffset = str(offset)
if offset >= 0:
strOffset = "+" + strOffset

View file

@ -329,7 +329,7 @@ class SnapcastWrapper(object):
f"Can't cast value {value} to {tag_mapping[key][1]}")
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}')
@ -926,7 +926,7 @@ class MPRISInterface(dbus.service.Object):
@ dbus.service.method(__player_interface, in_signature='x', out_signature='')
def Seek(self, offset):
logger.debug(f'Seek {offset}')
snapcast_wrapper.control("Seek", {"Offset": offset})
snapcast_wrapper.control("Seek", {"Offset": float(offset) / 1000000})
# status = mpd_wrapper.status()
# current, end = status['time'].split(':')
# current = int(current)
@ -944,7 +944,7 @@ class MPRISInterface(dbus.service.Object):
def SetPosition(self, trackid, position):
logger.debug(f'SetPosition TrackId: {trackid}, Position: {position}')
snapcast_wrapper.control(
"SetPosition", {"TrackId": trackid, "Position": position})
"SetPosition", {"TrackId": trackid, "Position": float(position) / 1000000})
self.Seeked(position)
# 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");
if (command == "SetPosition")
{
if (!request.params().has("params") || !request.params().get("params").contains("Position") || !request.params().get("params").contains("TrackId"))
throw SnapException("SetPosition requires parameters 'Position' and 'TrackId'");
if (!request.params().has("params") || !request.params().get("params").contains("Position"))
throw SnapException("SetPosition requires parameters 'Position' and optionally 'TrackId'");
if (!properties_.can_seek)
throw SnapException("CanSeek is false");
}