Some improvements in VLC

This commit is contained in:
Uriziel 2013-01-25 21:29:06 +01:00
parent 34354668ee
commit e7f34e2e79
3 changed files with 22 additions and 20 deletions

View File

@ -53,6 +53,7 @@ MPC_LOCK_WAIT_TIME = 0.2
MPC_RETRY_WAIT_TIME = 0.01 MPC_RETRY_WAIT_TIME = 0.01
MPC_MAX_RETRIES = 30 MPC_MAX_RETRIES = 30
MPC_PAUSE_TOGGLE_DELAY = 0.05 MPC_PAUSE_TOGGLE_DELAY = 0.05
VLC_OPEN_MAX_WAIT_TIME = 10
#These are not changes you're looking for #These are not changes you're looking for
MPLAYER_SLAVE_ARGS = [ '-slave', '-nomsgcolor', '-msglevel', 'all=1:global=4'] MPLAYER_SLAVE_ARGS = [ '-slave', '-nomsgcolor', '-msglevel', 'all=1:global=4']

View File

@ -69,6 +69,7 @@ en = {
"not-json-error" : "Not a json encoded string\n", "not-json-error" : "Not a json encoded string\n",
"hello-arguments-error" : "Not enough Hello arguments\n", "hello-arguments-error" : "Not enough Hello arguments\n",
"version-mismatch-error" : "Mismatch between versions of client and server\n", "version-mismatch-error" : "Mismatch between versions of client and server\n",
"vlc-failed-connection": "Failed to connect to VLC. If you have not installed syncplay-vlc.lua then please follow the VLC instructions at http://syncplay.pl/, if you have, please try again",
# Client arguments # Client arguments
"argument-description" : 'Solution to synchronize playback of multiple MPlayer and MPC-HC instances over the network.', "argument-description" : 'Solution to synchronize playback of multiple MPlayer and MPC-HC instances over the network.',

View File

@ -7,6 +7,7 @@ import os
import random import random
import socket import socket
import asynchat, asyncore import asynchat, asyncore
from syncplay.messages import getMessage
class VlcPlayer(BasePlayer): class VlcPlayer(BasePlayer):
speedSupported = True speedSupported = True
@ -25,7 +26,6 @@ class VlcPlayer(BasePlayer):
self._duration = None self._duration = None
self._filename = None self._filename = None
self._filepath = None self._filepath = None
self._playerReady = True
self._durationAsk = threading.Event() self._durationAsk = threading.Event()
self._filenameAsk = threading.Event() self._filenameAsk = threading.Event()
@ -34,15 +34,18 @@ class VlcPlayer(BasePlayer):
self._pausedAsk = threading.Event() self._pausedAsk = threading.Event()
self._vlcready = threading.Event() self._vlcready = threading.Event()
try: try:
self._listener = self.__Listener(self, playerPath, filePath, args) self._listener = self.__Listener(self, playerPath, filePath, args, self._vlcready)
except ValueError: except ValueError:
self._client.ui.showMessage("Failed to load VLC") self._client.ui.showMessage(getMessage("en", "vlc-failed-connection"))
self._client.stop(True) self._client.stop(True)
return return
self._listener.setDaemon(True) self._listener.setDaemon(True)
self._listener.start() self._listener.start()
self._vlcready.wait() if(not self._vlcready.wait(constants.VLC_OPEN_MAX_WAIT_TIME)):
self._preparePlayer() self._vlcready.set()
self._client.ui.showMessage(getMessage("en", "vlc-failed-connection"))
self._client.stop(True)
self._client.initPlayer(self)
def _fileUpdateClearEvents(self): def _fileUpdateClearEvents(self):
self._durationAsk.clear() self._durationAsk.clear()
@ -61,12 +64,6 @@ class VlcPlayer(BasePlayer):
self._client.updateFile(self._filename, self._duration, self._filepath) self._client.updateFile(self._filename, self._duration, self._filepath)
self.setPaused(self._client.getGlobalPaused()) self.setPaused(self._client.getGlobalPaused())
self.setPosition(self._client.getGlobalPosition()) self.setPosition(self._client.getGlobalPosition())
def _preparePlayer(self):
self.setPaused(self._client.getGlobalPaused())
self.setPosition(self._client.getGlobalPosition())
self._client.initPlayer(self)
self._playerReady = True
def askForStatus(self): def askForStatus(self):
self._positionAsk.clear() self._positionAsk.clear()
@ -161,11 +158,10 @@ class VlcPlayer(BasePlayer):
self._positionAsk.set() self._positionAsk.set()
self._vlcready.set() self._vlcready.set()
self._pausedAsk.set() self._pausedAsk.set()
self.__running = False
self._client.stop(False) self._client.stop(False)
class __Listener(threading.Thread, asynchat.async_chat): class __Listener(threading.Thread, asynchat.async_chat):
def __init__(self, playerController, playerPath, filePath, args): def __init__(self, playerController, playerPath, filePath, args, vlcReady):
self.__playerController = playerController self.__playerController = playerController
call = [playerPath] call = [playerPath]
if(filePath): if(filePath):
@ -173,7 +169,8 @@ class VlcPlayer(BasePlayer):
call.extend(playerController.SLAVE_ARGS) call.extend(playerController.SLAVE_ARGS)
if(args): if(args):
call.extend(args) call.extend(args)
self._vlcready = vlcReady
self.__process = subprocess.Popen(call, stderr=subprocess.PIPE) self.__process = subprocess.Popen(call, stderr=subprocess.PIPE)
threading.Thread.__init__(self, name="VLC Listener") threading.Thread.__init__(self, name="VLC Listener")
asynchat.async_chat.__init__(self) asynchat.async_chat.__init__(self)
@ -181,22 +178,25 @@ class VlcPlayer(BasePlayer):
self._ibuffer = [] self._ibuffer = []
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self._sendingData = threading.Lock() self._sendingData = threading.Lock()
self.connect(('localhost', self.__playerController.vlcport))
def initiate_send(self): def initiate_send(self):
with self._sendingData: with self._sendingData:
asynchat.async_chat.initiate_send(self) asynchat.async_chat.initiate_send(self)
def run(self): def run(self):
self.__running = True self._vlcready.clear()
self.connect(('localhost', self.__playerController.vlcport))
asyncore.loop() asyncore.loop()
def handle_connect(self):
asynchat.async_chat.handle_connect(self)
self._vlcready.set()
def collect_incoming_data(self, data): def collect_incoming_data(self, data):
self._ibuffer.append(data) self._ibuffer.append(data)
def close(self): def handle_close(self):
self.__running = False asynchat.async_chat.handle_close(self)
self.__playerController.drop() self.__playerController.drop()
def found_terminator(self): def found_terminator(self):
@ -205,6 +205,6 @@ class VlcPlayer(BasePlayer):
self._ibuffer = [] self._ibuffer = []
def sendLine(self, line): def sendLine(self, line):
if(self.__running): if(self.connected):
# print "send: {}".format(line) # print "send: {}".format(line)
self.push(line + "\n") self.push(line + "\n")