mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-13 00:56:44 +02:00
Send control command as parameter
This commit is contained in:
parent
4064766818
commit
de9e3496df
2 changed files with 37 additions and 30 deletions
|
@ -366,35 +366,38 @@ class MPDWrapper(object):
|
||||||
id = request['id']
|
id = request['id']
|
||||||
[interface, cmd] = request['method'].split('.', 1)
|
[interface, cmd] = request['method'].split('.', 1)
|
||||||
if interface == 'Player':
|
if interface == 'Player':
|
||||||
success = True
|
if cmd == 'Control':
|
||||||
if cmd == 'Next':
|
success = True
|
||||||
self.next()
|
command = request['params']['command']
|
||||||
elif cmd == 'Previous':
|
params = request['params'].get('params', {})
|
||||||
self.previous()
|
if command == 'Next':
|
||||||
elif cmd == 'Play':
|
self.next()
|
||||||
self.play()
|
elif command == 'Previous':
|
||||||
elif cmd == 'Pause':
|
self.previous()
|
||||||
self.pause(1)
|
elif command == 'Play':
|
||||||
elif cmd == 'PlayPause':
|
|
||||||
if self.status()['state'] == 'play':
|
|
||||||
self.pause(1)
|
|
||||||
else:
|
|
||||||
self.play()
|
self.play()
|
||||||
elif cmd == 'Stop':
|
elif command == 'Pause':
|
||||||
self.stop()
|
self.pause(1)
|
||||||
elif cmd == 'SetPosition':
|
elif command == 'PlayPause':
|
||||||
trackid = request['params']['TrackId']
|
if self.status()['state'] == 'play':
|
||||||
trackid = trackid.rsplit('/', 1)[1]
|
self.pause(1)
|
||||||
position = request['params']['Position']
|
else:
|
||||||
position = int(position) / 1000000
|
self.play()
|
||||||
self.seekid(int(trackid), position)
|
elif command == 'Stop':
|
||||||
elif cmd == 'Seek':
|
self.stop()
|
||||||
offset = request['params']['Offset']
|
elif command == 'SetPosition':
|
||||||
offset = int(offset) / 1000000
|
trackid = params['TrackId']
|
||||||
strOffset = str(offset)
|
trackid = trackid.rsplit('/', 1)[1]
|
||||||
if offset >= 0:
|
position = params['Position']
|
||||||
strOffset = "+" + strOffset
|
position = int(position) / 1000000
|
||||||
self.seekcur(strOffset)
|
self.seekid(int(trackid), position)
|
||||||
|
elif command == 'Seek':
|
||||||
|
offset = params['Offset']
|
||||||
|
offset = int(offset) / 1000000
|
||||||
|
strOffset = str(offset)
|
||||||
|
if offset >= 0:
|
||||||
|
strOffset = "+" + strOffset
|
||||||
|
self.seekcur(strOffset)
|
||||||
elif cmd == 'SetProperty':
|
elif cmd == 'SetProperty':
|
||||||
property = request['params']
|
property = request['params']
|
||||||
logger.info(f'SetProperty: {property}')
|
logger.info(f'SetProperty: {property}')
|
||||||
|
@ -402,7 +405,7 @@ class MPDWrapper(object):
|
||||||
self.random(int(property['shuffle']))
|
self.random(int(property['shuffle']))
|
||||||
if 'loopStatus' in property:
|
if 'loopStatus' in property:
|
||||||
value = property['loopStatus']
|
value = property['loopStatus']
|
||||||
if value == "playlist":
|
if value == "playlist ":
|
||||||
self.repeat(1)
|
self.repeat(1)
|
||||||
if self._can_single:
|
if self._can_single:
|
||||||
self.single(0)
|
self.single(0)
|
||||||
|
|
|
@ -83,6 +83,7 @@ void CtrlScript::send(const jsonrpcpp::Request& request, const OnResponse& respo
|
||||||
request_callbacks_[request.id()] = response_handler;
|
request_callbacks_[request.id()] = response_handler;
|
||||||
|
|
||||||
std::string msg = request.to_json().dump() + "\n";
|
std::string msg = request.to_json().dump() + "\n";
|
||||||
|
LOG(INFO, SCRIPT_LOG_TAG) << "Sending request: " << msg;
|
||||||
in_.write(msg.data(), msg.size());
|
in_.write(msg.data(), msg.size());
|
||||||
in_.flush();
|
in_.flush();
|
||||||
}
|
}
|
||||||
|
@ -485,7 +486,10 @@ void PcmStream::control(const jsonrpcpp::Request& request, const CtrlScript::OnR
|
||||||
LOG(INFO, LOG_TAG) << "Stream '" << getId() << "' received command: '" << command << "', params: '" << request.params().to_json() << "'\n";
|
LOG(INFO, LOG_TAG) << "Stream '" << getId() << "' received command: '" << command << "', params: '" << request.params().to_json() << "'\n";
|
||||||
if (ctrl_script_)
|
if (ctrl_script_)
|
||||||
{
|
{
|
||||||
jsonrpcpp::Request req(++req_id_, "Player." + command, request.params().has("params") ? request.params().get("params") : json{});
|
jsonrpcpp::Parameter params{"command", command};
|
||||||
|
if (request.params().has("params"))
|
||||||
|
params.add("params", request.params().get("params"));
|
||||||
|
jsonrpcpp::Request req(++req_id_, "Player.Control", params);
|
||||||
ctrl_script_->send(req, response_handler);
|
ctrl_script_->send(req, response_handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue