I am having an issue where I've implemented a class to listen when onPlayBackEnded has ended, but it does not appear to be firing. This is my code:
http://mirrors.kodi.tv/docs/python-docs/13.0-gotham/xbmc.html#Player-onPlayBackEnded
class BWPlayer(xbmc.Player) :
def __init__ (self):
xbmc.Player.__init__(self)
def onPlayBackStarted(self):
print("Strted")
def onPlayBackEnded(self):
xbmcgui.Dialog().ok(addonname, "Done Playing")
def onPlayBackStopped(self):
print("Strted")
def onPlayBackPaused(self):
print("Strted")
def onPlayBackResumed(self):
print("Strted")
player = BWPlayer()
player.play(item='file.mp4')
Did I implement something wrong?
'player.play' is not a blocking call which means that your script will continue to run to the very end, and then your player
instance goes out of scope and is garbage-collected.
You need to create some kine of long-running loop to prevent your script from exiting. Something like this:
player.play(item='file.mp4')
xbmc.sleep(500) # Wait until playback starts
while player.isPlaying():
xbmc.sleep(500)
If you need your script to run forever (until Kodi exits) then you will need something like this:
monitor = xbmc.Monitor()
monitor.waitForAbort()
monitor.waitForAbort()
will block your script and prevent it from exiting while Kodi is running.