Ejemplo n.º 1
0
def testServerAndPlayerIntegration():
    host, port = 'localhost', 5000
    server = RequestServer((host, port), player=LocalPlayer(), handler_class=YamRequestHandler)
    server.start()

    client = RemoteClient(host, port)
    client.sendRequest('player;getState')

    server.stop()
Ejemplo n.º 2
0
def testClientAndServer():
    host, port = 'localhost', 5000
    server = RequestServer((host, port), handler_class=EchoRequestHandler)
    server.start()

    client = RemoteClient(host, port)
    client.sendRequest('HELLO WORLD')

    import time
    time.sleep(1)
    client.sendRequest('Second message')

    server.stop()
    return 0
Ejemplo n.º 3
0
 def __init__(self, host, port, remoteClient=None):
     QtCore.QObject.__init__(self)
     if not remoteClient:
         self.remoteClient = RemoteClient(host, port)
     else:
         self.remoteClient = remoteClient
Ejemplo n.º 4
0
class RemotePlayer(QtCore.QObject):
    """
    The RemotePlayer redirects all requests to an host using a RemoteClient
    """

    stateChanged = QtCore.Signal(str)

    # Emit a signal whenever the player source changes
    sourceChanged = QtCore.Signal(Track)

    ticked = QtCore.Signal(int)

    def __init__(self, host, port, remoteClient=None):
        QtCore.QObject.__init__(self)
        if not remoteClient:
            self.remoteClient = RemoteClient(host, port)
        else:
            self.remoteClient = remoteClient

    def setRemoteClient(self, remoteClient):
        self.remoteClient = remoteClient

    def setParent(self, parent):
        print "Remote player has no use for a parent..."

    def seek(self, timeInMs):
        request = "player;seek;{0}".format(timeInMs)
        answer = self.remoteClient.sendRequest(request)
        return answer

    def setHeadless(self):
        print "Remote player has no use for a parent..."

    def currentPlaylist(self):
        print "Play list requested"
        return self._playlist

    def hasNextTrack(self):
        request = "player;hasNextTrack"
        result = bool(self.remoteClient.sendRequest(request))
        print result
        return result

    def hasPreviousTrack(self):
        request = "player;hasPreviousTrack"
        return bool(self.remoteClient.sendRequest(request))

    def getCurrentTrack(self):
        request = "player;getCurrentTrack"
        result = self.remoteClient.sendRequest(request)
        return Mock(eval(result))

    def playTrack(self, track):
        request = "player;playTrack;{0}".format(track)
        return self.remoteClient.sendRequest(request)

    def playTracks(self, tracks=[]):
        request = "player;playTracks;{0}".format(self._encodeTracks(tracks))
        return self.remoteClient.sendRequest(request)

    def queueTrack(self, track, emit=True):
        request = "player;queueTrack;{0}".format(track)
        return self.remoteClient.sendRequest(request)

    def queueTracks(self, tracks):
        request = "player;queueTracks;{0}".format(self._encodeTracks(tracks))
        return self.remoteClient.sendRequest(request)

    def playNextTrack(self):
        request = "player;playNextTrack"
        return self.remoteClient.sendRequest(request)

    def playPreviousTrack(self):
        request = "player;playPreviousTrack"
        return self.remoteClient.sendRequest(request)

    def stop(self):
        request = "player;stop"
        return self.remoteClient.sendRequest(request)

    def resume(self):
        request = "player;resume"
        return self.remoteClient.sendRequest(request)

    def pause(self):
        request = "player;pause"
        return self.remoteClient.sendRequest(request)

    def getCurrentTime(self):
        request = "player;getCurrentTime"
        return self.remoteClient.sendRequest(request)

    def getState(self):
        request = "player;getFullState"
        return Mock(eval(self.remoteClient.sendRequest(request)))

    def togglePlayState(self):
        request = "player;togglePlayState"
        return self.remoteClient.sendRequest(request)

    def notifyStateChanged(self):
        print "changed"

    def registerToStateChanges(self, target):
        request = "player;registerToStateChanges;{0}".format(target)
        return self.remoteClient.sendRequest(request)

    def unregisterToStateChanges(self, target):
        request = "player;unregisterToStateChanges;{0}".format(target)
        return self.remoteClient.sendRequest(request)

    def getFullState(self):
        request = "player;getFullState"
        return Mock(eval(self.remoteClient.sendRequest(request)))

    def _encodeTracks(self, tracks):
        requestData = ""
        for track in tracks:
            requestData = requestData + str(track) + "|"
        requestData = requestData[:-1]  # remove last |
        return requestData