Send control command as parameter

This commit is contained in:
badaix 2021-06-07 23:50:20 +02:00
parent 4064766818
commit de9e3496df
2 changed files with 37 additions and 30 deletions

View file

@ -366,30 +366,33 @@ 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':
if cmd == 'Control':
success = True success = True
if cmd == 'Next': command = request['params']['command']
params = request['params'].get('params', {})
if command == 'Next':
self.next() self.next()
elif cmd == 'Previous': elif command == 'Previous':
self.previous() self.previous()
elif cmd == 'Play': elif command == 'Play':
self.play() self.play()
elif cmd == 'Pause': elif command == 'Pause':
self.pause(1) self.pause(1)
elif cmd == 'PlayPause': elif command == 'PlayPause':
if self.status()['state'] == 'play': if self.status()['state'] == 'play':
self.pause(1) self.pause(1)
else: else:
self.play() self.play()
elif cmd == 'Stop': elif command == 'Stop':
self.stop() self.stop()
elif cmd == 'SetPosition': elif command == 'SetPosition':
trackid = request['params']['TrackId'] trackid = params['TrackId']
trackid = trackid.rsplit('/', 1)[1] trackid = trackid.rsplit('/', 1)[1]
position = request['params']['Position'] position = params['Position']
position = int(position) / 1000000 position = int(position) / 1000000
self.seekid(int(trackid), position) self.seekid(int(trackid), position)
elif cmd == 'Seek': elif command == 'Seek':
offset = request['params']['Offset'] offset = params['Offset']
offset = int(offset) / 1000000 offset = int(offset) / 1000000
strOffset = str(offset) strOffset = str(offset)
if offset >= 0: if offset >= 0:
@ -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)

View file

@ -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);
} }
} }