Python Pyglet player on_eos decorator not being called -
i'm trying have python media player automatically queue , play random source after current source ends. end, i've been wrestling player event on_eos
import pyglet import random import os #global variable declarations musicdir = "" musiclist = "" currentindex = 0 maxsongs = 0 player = pyglet.media.player() player.eos_action = pyglet.media.player.eos_next @player.event def on_eos(): randomsong() def getmusicdir(): global musicdir global musiclist global maxsongs musicdir = os.path.abspath("c:\music") musiclist = os.listdir(musicdir) maxsongs = len(musiclist) def randomsong(): global currentindex global musiclist global player currentindex = random.randint(0, maxsongs-1) player.queue(pyglet.media.load(musicdir + "/" + musiclist[currentindex])) player.next() player.play() getmusicdir() currentindex = random.randint(0, maxsongs-1) player.queue(pyglet.media.load(musicdir + "/" + musiclist[currentindex])) player.play()
however on_eos() event never called. i've looked through pyglet documentation, , tried
@player.event('on_eos')
and defining sublcass of player defines on_eos, no effect. error on_eos never being dispatched, or missing something?
this should work you:
player = pyglet.media.player() # our event handling function def on_eos(): print("on player eos") player.push_handlers(on_eos)
Comments
Post a Comment