diff --git a/.gitignore b/.gitignore index aa8746f..a528655 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,6 @@ build/output/ venv/ -config.py \ No newline at end of file +config.py + +dev/test.mp3 \ No newline at end of file diff --git a/player.py b/player.py index 6bf81b0..54bea85 100644 --- a/player.py +++ b/player.py @@ -325,7 +325,19 @@ class Player(): elif self.isInit: - if (self.last_msg == 'LOADED?'): + message_types: Dict[str, Callable[any, bool]] = { # TODO Check Types + "PLAY": lambda: self._retMsg(self.play()), + "PAUSE": lambda: self._retMsg(self.pause()), + "UNPAUSE": lambda: self._retMsg(self.unpause()), + "STOP": lambda: self._retMsg(self.stop()), + "UNLOAD": lambda: self._retMsg(self.unload()), + "STATUS": lambda: self._retMsg(self.status, True) + } + + if self.last_msg in message_types.keys(): + message_types[self.last_msg]() + + elif (self.last_msg == 'LOADED?'): self._retMsg(self.isLoaded) continue @@ -333,18 +345,6 @@ class Player(): split = self.last_msg.split(":") self._retMsg(self.add_to_plan(json.loads(":".join(split[1:])))) - elif (self.last_msg == 'PLAY'): - self._retMsg(self.play()) - - elif (self.last_msg == 'PAUSE'): - self._retMsg(self.pause()) - - elif (self.last_msg == 'UNPAUSE'): - self._retMsg(self.unpause()) - - elif (self.last_msg == 'STOP'): - self._retMsg(self.stop()) - elif (self.last_msg == 'QUIT'): self.running = False continue @@ -357,12 +357,6 @@ class Player(): split = self.last_msg.split(":") self._retMsg(self.load(int(split[1]))) - elif (self.last_msg == 'UNLOAD'): - self._retMsg(self.unload()) - - elif (self.last_msg == 'STATUS'): - self._retMsg(self.status, True) - else: self._retMsg("Unknown Command") else: