def mpd_event_listener(self): """ Starts the loop for listening MPD events """ while self.playing: c = MpdConnection(self.host, self.port, reader_flags='r', encoding=None) c.connect() if not c.writer: continue c.writer.write(IDLE + "\n") c.writer.flush() line = None try: line = c.reader.readline() # blocking line logging.debug("line from idle: " + line) except Exception as e: logging.debug(e) if line and "mixer" in line: volume = self.get_volume() self.notify_volume_listeners(volume) continue self.dispatch_callback(line) c.disconnect()
def start_client(self): """ Start client thread """ self.conn = MpdConnection(self.host, self.port) self.conn.connect() thread = threading.Thread(target=self.mpd_event_listener) thread.start()