From 0d3ca61cbe27f2ddbb5fc08558ea4aee5ee9e671 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Tue, 27 Dec 2016 19:24:32 +0100 Subject: [PATCH] mute handling also in --- server/server.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/server/server.py b/server/server.py index 8c9a4f6..d58f44a 100644 --- a/server/server.py +++ b/server/server.py @@ -41,8 +41,8 @@ class MpvSockParser(object): def __init__(self): self.listeners = [] self.playerState = { - "totalDuration": 42, - "currentDuration": 23, + "totalDuration": 42.0, + "currentDuration": 23.0, "volume": 66, "fileName": "No Data Yet", "isPlaying": False @@ -65,8 +65,9 @@ class MpvSockParser(object): self.poller.sendData('{"command":["observe_property",2,"volume"]}') self.poller.sendData('{"command":["observe_property",3,"filename"]}') self.poller.sendData('{"command":["observe_property",4,"duration"]}') - self.poller.sendData('{"command":["observe_property",4,"duration"]}') - self.poller.sendData('{ "command": ["get_property", "pause"], "request_id":10}') + self.poller.sendData('{"command":["observe_property",5,"mute"]}') + self.poller.sendData('{"command":["get_property","pause"],"request_id":10}') + self.poller.sendData('{"command":["get_property","mute"],"request_id":11}') self.poller.start() @@ -92,6 +93,8 @@ class MpvSockParser(object): self.playerState['currentDuration'] = curCur if data['event'] == 'property-change' and data['name'] == 'volume': self.playerState['volume'] = int(data['data']) + if data['event'] == 'property-change' and data['name'] == 'mute': + self.playerState['isMuted'] = data['data'] if data['event'] == 'property-change' and data['name'] == 'filename': self.playerState['fileName'] = data['data'] if data['event'] == 'property-change' and data['name'] == 'duration': @@ -107,18 +110,23 @@ class MpvSockParser(object): def processCommand(self, data): if "request_id" in data and data['request_id'] == 10: - print 'synced pause state' self.playerState['isPlaying'] = not data["data"] + if "request_id" in data and data['request_id'] == 11: + self.playerState['isMuted'] = data["data"] def sendCommand(self, command): if command["command"] == "play": self.poller.sendData('{ "command": ["set_property", "pause", false] }') if command["command"] == "pause": self.poller.sendData('{ "command": ["set_property", "pause", true] }') + if command["command"] == "mute": + self.poller.sendData('{ "command": ["set_property", "mute", true] }') + if command["command"] == "unmute": + self.poller.sendData('{ "command": ["set_property", "mute", false] }') if command["command"] == "seek": self.poller.sendData('{ "command": ["seek", "%s", "absolute"] }'%command['seekValue']) if command["command"] == "volume": - self.poller.sendData('{ "command": ["set", "volume", %s] }'%command['volume']) + self.poller.sendData('{ "command": ["set", "volume", "%s"] }'%command['volume']) if command["command"] == "seekChapter": if command['direction'] == 'forward': direction = +1 @@ -130,7 +138,7 @@ class WSHandler(WebSocket): def handleMessage(self): global mpvParser command = json.loads(self.data) - print 'got commadn %s'%command + print 'got command %s'%command mpvParser.sendCommand(command) def handleConnected(self): global mpvParser