Simple Addon Development
#1
Hi,

Im trying to do a simple development that will simply

1. Startup automatically
2. Listen for Play, Pause, Resume Events
3. Hit a URL when it gets these events

Does anyone have a very simple structure of an addon that might help me gets started.

All the ones I've looked at are so complex that its hard to decipher.
Reply
#2
Hi @plucka 

You may find autosub a decent starting point: https://github.com/fnord12/service.autosub

It runs as a service (starts up automatically).  It has a Player class with an onAVChange function which will get automatically triggered on Play and Resume (not sure about Pause).  And it's a relatively small plugin so you should be able to clear out the parts you don't need.  Basically everything's in the default.py file.

You may also find this documentation useful.  It shows the functions that can be triggered from the Player class.  In addition to onAVChange, you'll see there's onAVStarted, onPlayBackPaused, onPlayBackResume

https://codedocs.xyz/xbmc/xbmc/group__py...bf538a2ba6

In terms of triggering a URL, i'm not able to help.
Reply
#3
Thanks

Im almost there, that was very helpful.

The Stopped and Ended events never seem to fire however, any idea what im doing wrong?

class Kodi_Player(xbmc.Player):
    
    def __init__( self, *args ):
        pass
        
    def onAVStarted(self):
        debug('entering onAVStarted')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onAVStarted', 'Yes')
            
    def onPlayBackPaused(self):
        debug('entering onPlayBackPaused')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onPlayBackPaused', 'Yes')
            
    def onPlayBackResumed(self):
        debug('entering onPlayBackResumed')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onPlayBackResumed', 'Yes')

    def onPlayBackEnded(self):
        debug('entering onPlayBackEnded')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onPlayBackEnded', 'Yes')

    def onPlayBackStopped(self):
        debug('entering onPlayBackStopped')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onPlayBackStopped', 'Yes')
Reply
#4
(2020-07-02, 05:24)plucka Wrote: Thanks

Im almost there, that was very helpful.

The Stopped and Ended events never seem to fire however, any idea what im doing wrong?

class Kodi_Player(xbmc.Player):
    
    def __init__( self, *args ):
        pass
        
    def onAVStarted(self):
        debug('entering onAVStarted')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onAVStarted', 'Yes')
            
    def onPlayBackPaused(self):
        debug('entering onPlayBackPaused')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onPlayBackPaused', 'Yes')
            
    def onPlayBackResumed(self):
        debug('entering onPlayBackResumed')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onPlayBackResumed', 'Yes')

    def onPlayBackEnded(self):
        debug('entering onPlayBackEnded')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onPlayBackEnded', 'Yes')

    def onPlayBackStopped(self):
        debug('entering onPlayBackStopped')
        if self.isPlayingVideo():
            xbmcgui.Dialog().ok('onPlayBackStopped', 'Yes')

ignore that just needed to remove the if self.isPlayingVideo()
Reply
#5
service.py  (not tested)
Code:
import xbmc
import urllib2

URL = 'http://127.0.0.1/'

class Player(xbmc.Player):        
    def onAVStarted(self):
        response = urllib2.urlopen(URL + 'playback_started')
            
    def onPlayBackPaused(self):
        response = urllib2.urlopen(URL + 'playback_paused')
            
    def onPlayBackResumed(self):
        response = urllib2.urlopen(URL + 'playback_resumed')

    def onPlayBackEnded(self):
        response = urllib2.urlopen(URL + 'playback_ended')

    def onPlayBackStopped(self):
        response = urllib2.urlopen(URL + 'playback_stopped')

player = Player()
monitor = xbmc.Monitor()
while not monitor.abortRequested():
    monitor.waitForAbort(10)
Reply



Logout Mark Read Team Forum Stats Members Help
Simple Addon Development0
This forum uses Lukasz Tkacz MyBB addons.