Difference between revisions of "Service add-ons"

From Official Kodi Wiki
Jump to navigation Jump to search
Line 35: Line 35:
             # Abort was requested while waiting. We should exit
             # Abort was requested while waiting. We should exit
         xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGNOTICE)
         xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGDEBUG)

Revision as of 16:04, 15 August 2021

Service addons will be automatically started when a user profile logs in or on Kodi startup, and stopped when the user profile logs out. These addons must offer the xbmc.service extension point. Here's a typical example of the addon.xml the addon needs to provide:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.example"
       name="Example service"
    <import addon="xbmc.python" version="2.1.0"/>
  <extension point="xbmc.service" library="service.py" />
  <extension point="xbmc.addon.metadata">
    <summary lang="en"></summary>

If your addon is meant to be run while Kodi is running, you need to periodically check if Kodi is exiting. The addon is responsible for terminating when Kodi wants to exit. This can be checked by creating a xbmc.Monitor instance and calling the abortRequested() method. To wait for this event instead, call waitForAbort().

Example service that prints "hello addon!" every 10 second until Kodi exits:

import time
import xbmc

if __name__ == '__main__':
    monitor = xbmc.Monitor()
    while not monitor.abortRequested():
        # Sleep/wait for abort for 10 seconds
        if monitor.waitForAbort(10):
            # Abort was requested while waiting. We should exit
        xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGDEBUG)

Gotham and earlier

abortRequested() and waitForAbort() are new in Helix. In Gotham and earlier, use xbmc.sleep and check the xbmc.abortRequested attribute periodically.


import xbmc
if __name__ == '__main__':
    while not xbmc.abortRequested:
        # some code

Prior to Kodi 18 Leia there was an additional option start="startup" that would start the service add-on before the first profile login, but that functionality and usefulness were limited so this option was removed.