2011-06-23, 16:24
Hi
I'm working on a multi-room audio addon which is giving me a headache. I'm relatively new to python which i'm sure is part of the problem.
Problem:
htpc 1 running my my addon in listener mode waits for udp note
htpc 2 running same addon in master mode will when it's started send udp data containing the path of the current playing song and the seektime in fractional seconds.
I suspected that htpc 1 wouldn't be playing slighty delayed to htpc 2 because of network lag and loading etc but htpc 1 is acctually ahead by 1-1.5 seconds which doesn't make any sense to me! Hope you can help explain this
Just ignore the ntp stuff the problem was there before i implemented that aswell.
I'm working on a multi-room audio addon which is giving me a headache. I'm relatively new to python which i'm sure is part of the problem.
Problem:
htpc 1 running my my addon in listener mode waits for udp note
htpc 2 running same addon in master mode will when it's started send udp data containing the path of the current playing song and the seektime in fractional seconds.
I suspected that htpc 1 wouldn't be playing slighty delayed to htpc 2 because of network lag and loading etc but htpc 1 is acctually ahead by 1-1.5 seconds which doesn't make any sense to me! Hope you can help explain this
Code:
def ListenForOrders():
notification("soundway", "Awaiting your commands", 3000, __settings__.getAddonInfo("icon"))
while 1:
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(("", 1337))
data, address = server_socket.recvfrom(256)
datastring = str(data)
dataarray = datastring.split("|")
if dataarray[0] == "soundway":
if xbmc.getInfoLabel("Player.Filenameandpath") != dataarray[1]:
xbmc.Player().play(str(dataarray[1]))
seektime = float(dataarray[2])+((time.time()+OFFSET)-float(dataarray[3]))
xbmc.Player().seekTime(seektime)
def GiveOrders():
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
timetosend = time.time()+OFFSET
data = 'soundway|' + xbmc.getInfoLabel("Player.Filenameandpath") + '|' + str(xbmc.Player().getTime())+"|"+str(timetosend)
client_socket.sendto(data, ("192.168.1.254",1337))
client_socket.close()
client = NTPClient()
response = client.request('europe.pool.ntp.org', version=3)
OFFSET = response.offset
bMaster = False
if (__settings__.getSetting( "Master" ) == 'true'): bMaster = True
if bMaster == True:
GiveOrders()
else:
ListenForOrders()
Just ignore the ntp stuff the problem was there before i implemented that aswell.