Current time of playing video
#1
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)
Reply
#2
here's the code i used from poker timer ii.

Quote: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.



For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#3
(nuka1195 @ jan. 02 2006,15:07 Wrote: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.
Reply
#4
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

Quote:koshvideobroadcastserver.py
##################################################################
# broadcast current video to network
# coded by koshatul ([email protected])
#
##################################################################

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)

Quote:koshvideobroadcastclient.py
##################################################################
# receive current video from network
# coded by koshatul ([email protected])
#
##################################################################

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()



Reply

Logout Mark Read Team Forum Stats Members Help
Current time of playing video0