示例#1
0
 def __init__(self):
     self.__playlist_file = config.get_playlist_file()
     self.load_playlist()
     self.__ms = MediaScanner()
     if self.__queued is None:
         self.__queued = self.__ms.scan()
         self.save_playlist()
     self.__played = []
示例#2
0
    def check_remotes(self):
        while not self.remotes_termination.is_set():
            time.sleep(0.2)
            if self.remote_event.is_set():
                self.remote_event.clear()
                try:
                    cmd = self.remote_msg["command"]
                except KeyError:
                    continue

                if cmd[0] in self.media_control_methods:
                    exec("self.player." + cmd[0] + "()")
                elif cmd[0] in self.media_info_methods:
                    result = eval("self.player." + cmd[0] + "()")
                    if self.remote_msg["source"] == "bluetooth":
                        self.bt_remote.reply(result)
                elif cmd[0] == "bluetooth":
                    if cmd[1] == "attach":
                        if self.player.__class__.__name__ == "BtPlayer":
                            continue
                        tmp = BtPlayer(cmd[2])
                        tmp.run()
                        tmp.ready.wait()
                        self.player.stop()
                        self.player = tmp
                        print("bluetooth attached")
                    elif cmd[1] == "detach":
                        if self.player.__class__.__name__ != "BtPlayer":
                            continue
                        tmp = StoragePlayer()
                        tmp.run()
                        tmp.ready.wait()
                        self.player.stop()
                        self.player = tmp
                        print("bluetooth detached")
                elif cmd[0] == "system":
                    if cmd[1] == "poweroff":
                        self.player.pause()
                        call(["sudo", "poweroff"])
                    elif cmd[1] == "reboot":
                        call(["sudo", "reboot"])
                elif cmd[0] == "play":
                    if self.player.__class__.__name__ != "StoragePlayer":
                        continue
                    what = json.loads(self.remote_msg["data"])
                    self.player.play_on_demand(what)
                elif cmd[0] == "playlist":
                    try:
                        with open(config.get_playlist_file()
                                  ) as file:  # TODO: implement in player
                            pl = str(json.load(file))
                            self.bt_remote.reply(pl)
                    except FileNotFoundError:
                        pass
                elif cmd[0] == "library":
                    try:
                        with open(config.get_library_file()) as file:
                            lib = str(json.load(file))
                            self.bt_remote.reply(lib)
                    except FileNotFoundError:
                        pass
                elif cmd[0] == "config":
                    if cmd[1] == "get":
                        self.bt_remote.reply(config.to_json())
                    elif cmd[1] == "set":
                        cfg = self.remote_msg["data"]
                        self.apply_configuration(cfg)
                    elif cmd[
                            1] == "reload":  # TODO: remove. this is for testing purposes only
                        self.reload_configuration()
                else:
                    print("unknown command received:", cmd)
                self.remote_msg.clear()  # clean for next usage

        # Remote checker termination
        self.control_pipe.stop()
        self.bt_remote.stop()
        if self.gpio_remote is not None:
            self.gpio_remote.stop()