PDA

View Full Version : Current time of playing video


Koshatul
2006-01-02, 13:13
i'm working on a python script to braodcast via udp to the local network the current video playing and it's time.

my goal is so when i am watching something on my xbox in my lounge, i can pause it, move to my bedroom, and start the client, which will receive the broadcast and load the movie at the specified position.

i'm ok with most of it, but i have read the python descrption of the player object and it has the filename but not the current play time.

i haven't done too much testing yet, or poking around in it.

i was wondering if someone else knew where i can pull the current time out from.

(i use smb to watch my recorded tv and anime, so the filenames should be the same between the two)

Nuka1195
2006-01-02, 17:07
here's the code i used from poker timer ii.

def playwarning(alarm, sleeptime):
* *playalarm(alarm, sleeptime)

def playalarm(alarm, sleeptime):
* *current_file = getplayingfile()
* *current_time = getplayingtime()
* *xbmc.player().play(extraspath + alarm)
* *sleep(sleeptime)
* *playfile(current_file, current_time)
* *activategui()

def playfile(current_file, current_time):
* *if current_file == "{none}":
* * * *xbmc.player().stop()
* *else:
* * * *xbmc.player().play(current_file)
* * * *xbmc.player().seektime(current_time)

def getplayingfile():
* *if xbmc.player().isplayingaudio() or xbmc.player().isplayingvideo():
* * * *current_file = xbmc.player().getplayingfile()
* *else:
* * * *current_file = "{none}"
* *return current_file

def getplayingtime():
* *if xbmc.player().isplayingaudio() or xbmc.player().isplayingvideo():
* * * *current_time = xbmc.player().gettime()
* *else:
* * * *current_time = "{none}"
* *return current_time

def activategui():
* *if xbmc.player().isplayingaudio():
* * * *xbmc.executebuiltin('xbmc.activatewindow(2006)')
* *elif xbmc.player().isplayingvideo():
* * * *xbmc.executebuiltin('xbmc.activatewindow(2005)')
* *sleep(.5)



xbmcscripts.com has a more updated python docs than cvs, if that's where you got yours.

Koshatul
2006-01-03, 03:05
xbmcscripts.com has a more updated python docs than cvs, if that's where you got yours.
wow, the xbmcscripts.com reference is much better.
i got mine from the xbmc wiki link.

i'll post up the code later when i finish it.

i've only been playing with python for 2 days now, still getting used to the lack of { }'s

looks like your code already has alot of what i want to do anyway.

Koshatul
2006-01-03, 15:30
it isn't much, i have to add the "pretty parts" now.

the indenting got pretty badly stuffed, but you can guess pretty easily where it goes

koshvideobroadcastserver.py
################################################## ################
# broadcast current video to network
# coded by koshatul (kosh@nervhq.com)
#
################################################## ################

import socket
import xbmc

hostname = '255.255.255.255'
portnumber = 7131

playfile = ""
playtime = ""

while 1:
playplaying = false
if xbmc.player().isplayingaudio():
playfile = xbmc.player().getplayingfile()
playtime = xbmc.player().gettime()
playplaying = xbmc.player().isplayingaudio()
udpmsg = 'audio ' + playfile + '~' + str(playtime) + '~' + str(playplaying) + '~'
if xbmc.player().isplayingvideo():
playfile = xbmc.player().getplayingfile()
playtime = xbmc.player().gettime()
playplaying = xbmc.player().isplayingvideo()
udpmsg = 'video ' + playfile + '~' + str(playtime) + '~' + str(playplaying) + '~'
if playplaying:
s = socket.socket(socket.af_inet, socket.sock_dgram)
s.setsockopt (socket.sol_socket, socket.so_broadcast, 1)
s.connect((hostname, portnumber))
s.send(udpmsg)
s.close()
del s
sleep(30)


koshvideobroadcastclient.py
################################################## ################
# receive current video from network
# coded by koshatul (kosh@nervhq.com)
#
################################################## ################

import socket
import xbmc

portnumber = 7131

playfile = ""
playtime = ""

s = socket.socket(socket.af_inet, socket.sock_dgram)
try:
s.bind(('', portnumber))
except:
xbmc.output("couldn't be a udp server on port %d" % (portnumber))
exit
while true:
datagram = s.recv(1024)
if not datagram:
break
if datagram[:5] == "video":
tmpdatagram = datagram[6:]
playfile, playtime, playplaying, tmpeol = tmpdatagram.split('~')
#playfile = "f:\\video\\halo 2\\halo2.mpeg"
xbmc.output('playfile = "' + playfile + '"\n')
xbmc.output('playtime = "' + playtime + '"\n')
xbmc.player().play(playfile)
xbmc.player().seektime(float(playtime))
break
s.close()