2012-05-07, 17:02
This is my first time venturing into python and adding created, although I do have experience in VB/Pascal/Basic from my school days.
The point of the addon is to capture that state of media playback with a view to passing that info via python to an arduino to control various outside case LED's. The code below has been based on bits taken from others trying to capture playback state for various other reasons and it based on about an hours of learning during the day.
The code below starts up just fine, on starting some type of media playback (video or audio) it succesfully get onPlayBackStarted() and adds the 'LED turned on' part to the xbmc log. It also 'LED Script: Started Running' and 'LED Script: Stopped Running' parts when the script starts up and closes down.
The issue is with the play back stopping. It doesn't get onPlayBackEnded() or onPlaybackStopped events when the media stops.
I'm I doing anything obviously wrong (noob errors etc) or can anyone advise a better method of doing what i need? I'm afraid I know little about the backend of XMBC or decent python coding so I'm not sure where I can go from here other then messing with a bit of cut / paste code from other projects.
The point of the addon is to capture that state of media playback with a view to passing that info via python to an arduino to control various outside case LED's. The code below has been based on bits taken from others trying to capture playback state for various other reasons and it based on about an hours of learning during the day.
The code below starts up just fine, on starting some type of media playback (video or audio) it succesfully get onPlayBackStarted() and adds the 'LED turned on' part to the xbmc log. It also 'LED Script: Started Running' and 'LED Script: Stopped Running' parts when the script starts up and closes down.
The issue is with the play back stopping. It doesn't get onPlayBackEnded() or onPlaybackStopped events when the media stops.
Code:
import xbmc
class MyPlayer(xbmc.Player):
def __init__(self):
xbmc.Player.__init__(self)
def onPlayBackEnded(self):
xbmc.log("LED Script: Video Stopped - LED turned off")
def onPlayBackStarted(self):
xbmc.log("LED Script: Video Started - LED turned on")
def onPlaybackStopped(self):
xbmc.log("LED Script: Video Stopped - LED turned off")
xbmc.log("LED Script: Started Running")
player = MyPlayer()
while(not xbmc.abortRequested):
xbmc.sleep(100)
xbmc.log("LED Script: Finished Running")
I'm I doing anything obviously wrong (noob errors etc) or can anyone advise a better method of doing what i need? I'm afraid I know little about the backend of XMBC or decent python coding so I'm not sure where I can go from here other then messing with a bit of cut / paste code from other projects.