Addon develoment questions
#1
I have recently started using XBMC and am ready to start some addon development. I have developed plugins for other media center applications, but never in python. The first plugin I want to develop is fairy simple. I want to send a command to a separate application whenever a video begins playing. The actually communication can be a variety of methods (command line, HTTP, web service, etc) and I should be able to figure that part out. The part where I am not so sure about is with how to trigger this communication when a video starts playing. Are there any examples out there that show how to start a script based on the activity of xbmc (video/music playing/stopped/paused)? Any help pointing me in the right direction would be great.
Reply
#2
Welcome to the club hobbes487,

Unfortunately I've never created a Addon such as this and most likely will be of no help on the topic, but as you said your new to Python I figured I would point you in the right directions with the Language:

http://code.google.com/edu/languages/goo...hon-class/

These classes really helped me when I first started with Python about 5months ago.
Reply
#3
there's several options available depending on what you're exactly trying to accomplish.

if it's only video startup you're after, you could probably just add a button that will launch the addon to VideoFullScreen.xml of the skin you're using.

in case you also want to check for paused/stopped/ended, have a look at the player class.

for music, you'll have to take a slightly different approach to launch the addon,
as xbmc does not switch to a new window when playback starts.
so either have the skin start the addon at startup or look into creating a 'service addon'.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#4
ronie Wrote:if it's only video startup you're after, you could probably just add a button that will launch the addon to VideoFullScreen.xml of the skin you're using.

Thats not exactly what I am trying to do. I dont want to display anything on the screen and I dont want to require the user to press any kind of button. It would basically be a background script that gets kicked off when the video player starts/stops/pauses.
Reply
#5
hobbes487 Wrote:I dont want to display anything on the screen and I dont want to require the user to press any kind of button.

afaik there's no way to autostart a script on play/pause/stop.
scripts are usually started by the skin and for this to work you need to add a hidden button to one of the skin windows.
there's no need for the user to press this button (it won't even be visible),
the skin will make sure this button gets focused when the window opens
and the button will start the script automatically.

if you're looking for examples, many skins will start a couple of scripts at startup. This is done in Startup.xml, so just check out that file for a couple of skins.

so just create a script that will run continuously and use the player class i mentioned above to monitor for start/stop/pause events.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#6
For testing purposes I've written a script that observes the xbmc-player. If you declare this as a service, it can run in the background whenever xbmc starts.

Code:
import xbmc,xbmcgui

class MyPlayer(xbmc.Player):
    def __init__ (self):
        xbmc.Player.__init__(self)
        self.state = 'INIT'

    def onPlayBackStarted(self):
        self.state = 'PLAY'

    def onPlayBackEnded(self):
        self.state = 'END'

    def onPlayBackPaused(self):
        self.state = 'PAUSE'

    def onPlayBackResumed(self):
        self.state = 'RESUME'

    def onPlayBackStopped(self):
        self.state = 'STOP'

#-------
pl = MyPlayer()
state_media = 'OTHER'
last_state = ''

while(1):
    if pl.isPlayingAudio():
        state_media = 'AUDIO'
    if pl.isPlayingVideo():
        state_media = 'VIDEO'
    if pl.state == 'STOP' or pl.state == 'END':
        state_media = 'NONE'

    if (last_state != pl.state):
        dialog = xbmcgui.Dialog()
        dialog.ok('Status', 'Media: %s, Status: %s' % (state_media, pl.state))
        last_state = pl.state

    xbmc.sleep(1000)

For services see: http://forum.xbmc.org/showthread.php?tid=92751
Reply
#7
ronie Wrote:afaik there's no way to autostart a script on play/pause/stop.

That's too bad. I would have thought there was some kind of event system that plugins can listen for.


_BJ1 - This looks like the best possible solution. Just have a service that continually looks at the state of the video player. Thanks.
Reply

Logout Mark Read Team Forum Stats Members Help
Addon develoment questions0