示例#1
0
    def connect(self):

        # Try up to 10 times to connect to MPD
        self.connection_failed = 0
        self.dataclient = None

        logging.debug(u"Connecting to MPD service on {0}:{1}".format(
            self.server, self.port))

        while True:
            if self.connection_failed >= 10:
                logging.debug(u"Could not connect to MPD")
                break
            try:
                # Connection to MPD
                client = mpd.MPDClient(use_unicode=True)
                client.connect(self.server, self.port)

                self.dataclient = client
                break
            except:
                self.dataclient = None
                self.connection_failed += 1
                time.sleep(1)
        if self.dataclient is None:
            raise mpd.ConnectionError(u"Could not connect to MPD")
        else:
            logging.debug(u"Connected to MPD")
示例#2
0
def previousMPD(c):
    print("Previous Song")
    try:
        c.previous()
    except mpd.ConnectionError():
        print("MPD error setting previous song.")
        return False
    return True
示例#3
0
def nextMPD(c):
    print("Next Song")
    try:
        c.next()
    except mpd.ConnectionError():
        print("MPD error setting next song.")
        return False
    return True
示例#4
0
def StopMPD(c):
    WriteLog("Stopping MPD")
    try:
        c.clear()
        return True
    except mpd.ConnectionError():
        print("StopMPD: MPD error.")
        return False
示例#5
0
文件: urmpd.py 项目: sporkexec/urmpc
 def wrap(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except (socket.error, mpd.ConnectionError) as e:
         try:
             self._connect()
             return func(*args, **kwargs)
         except (socket.error, mpd.ConnectionError) as e:
             raise mpd.ConnectionError('Cannot establish connection')
示例#6
0
def ConnectMPD(c):
    try:
        c.connect(mpdhost, 6600)
        print("Connected to MDP version " + str(c.mpd_version) + ".")
    except mpd.ConnectionError():
        return False
    except socket.error:
        return False

    return True
示例#7
0
def SetVolumeMPD(c, vol):
    global nowVolume
    print("Set volume to " + str(vol) + ".")
    nowVolume = vol
    try:
        c.setvol(vol)
    except mpd.ConnectionError():
        print("MPD error setting volume.")
        return False
    return True
示例#8
0
 def fileno(self):
     if not self.connected:
         raise mpd.ConnectionError("Not connected")
     return self.client._sock.fileno()
示例#9
0
def DisconnectMPD(c):
    try:
        c.close()
        print("Disconnected from MDP version " + str(c.mpd_version) + ".")
    except mpd.ConnectionError():
        pass