Using onPlaybackStopped, onPlayBackStarted works but not Stopped?
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.

import xbmc

class MyPlayer(xbmc.Player):

    def __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.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.
Managed to get it to work after a bit more fiddling and searching this evening:

import xbmc

class XBMCPlayer( xbmc.Player ):

    def __init__( self, *args ):

    def onPlayBackStarted( self ):
        # Will be called when xbmc starts playing a file
        xbmc.log( "LED Status: Playback Started, LED ON" )

    def onPlayBackEnded( self ):
        # Will be called when xbmc stops playing a file
        xbmc.log( "LED Status: Playback Stopped, LED OFF" )

    def onPlayBackStopped( self ):
        # Will be called when user stops xbmc playing a file
        xbmc.log( "LED Status: Playback Stopped, LED OFF" )

player = XBMCPlayer()

while(not xbmc.abortRequested):

I don't understand why its works but i've tested it and it will add the xbmc.log entries on stop and start for both video and music so that's basically what I was after.
You can pass a player core so you need to tell the class to accept it. *args.

I have a patch that adds the other missing on playback events. If accepted it adds onplaybackspeedchanged, onplaybackseek, onplaybackseekchapter and onqueunextitem.
For python coding questions first see
dynamis_dk, any chance you can explain how you make this work in a service?
I made a try but it does not seem to bite.

Now looking at KNX
It is very closed to what I tried but I guess I missed something. Will give it a new try.
Thread Rating:
  • 0 Vote(s) - 0 Average

Logout Mark Read Team Forum Stats Members Help
Using onPlaybackStopped, onPlayBackStarted works but not Stopped?00