Service add-ons: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
No edit summary
(Update example to use helix api)
Line 1: Line 1:
<section begin="intro" />XBMC has now the possibility to automatically start addons on startup, making the autoexec.py file obselete. These special addons are called '''service''' addons.<section end="intro" />


Service addons must offer the '''xbmc.service''' extension point. Here's a typical example of the addon.xml the addon needs to provide:
Service addons will be automatically started when XBMC starts. These addons must offer the '''xbmc.service''' extension point. You can specify when you want your addon to start, using the '''start''' tag. If it's isn't here, your addon will automatically start after user login. If you want it to start on XBMC startup, you need to set the '''start''' tag to ''startup''. Here's a typical example of the addon.xml the addon needs to provide:


<source lang="xml">
<source lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.tv.betaseries"
<addon id="service.example"
       name="BetaSeries.com"
       name="Example service"
       version="0.1"
       version="1.0.0"
       provider-name="blinkseb (XBMC)">
       provider-name="">
   <requires>
   <requires>
     <import addon="xbmc.python" version="2.0"/>
     <import addon="xbmc.python" version="2.1.0"/>
   </requires>
   </requires>
   <extension point="xbmc.service"
   <extension point="xbmc.service" library="service.py" start="login">
            library="default.py" start="login">
   </extension>
   </extension>
   <extension point="xbmc.addon.metadata">
   <extension point="xbmc.addon.metadata">
     <platform>all</platform>
     <platform>all</platform>
     <summary lang="en">BetaSeries.com integration.</summary>
     <summary lang="en"></summary>
   </extension>
   </extension>
</addon>
</addon>
</source>
</source>


The addon will be automatically started when XBMC starts. You can specify when you want your addon to start, using the '''start''' tag. If it's isn't here, your addon will automatically start after user login. If you want it to start on XBMC startup, you need to set the '''start''' tag to '''startup'''.
If your addon is meant to be run while XBMC is running, you need to periodically check if XBMC is exiting. The addon is responsible for terminating when XBMC 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()'''.


'''Note 1: If your addon is meant to be run while XBMC is running, you need to periodically check if XBMC is exiting. To do that, you need to import the '''xbmc''' module, and check if '''xbmc.abortRequested''' is true. Typically, you should do something like that:
 
 
'''Note''': ''abortRequested()'' and ''waitForAbort()'' are new in Helix. In Gotham, use ''xbmc.sleep'' and check the ''xbmc.abortRequested'' attribute periodically.
 
 
 
Example service that prints "hello addon!" every 10 second until XBMC exits:


<source lang="python">
<source lang="python">
import xbmc;
import time
import xbmc


while (not xbmc.abortRequested):
if __name__ == '__main__':
  some code
    monitor = xbmc.Monitor()
   
    while not monitor.waitForAbort(10):
        xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGDEBUG)
</source>
</source>


'''Note 2: services addons are currently limited to python only'''
'''Note 3: The addon won't be launched if it's disabled by the user.'''
You'll find more informations about addons [[Add-ons for XBMC (Developement)|here]]


[[Category:How-to]]
[[Category:How-to]]
[[Category:Add-on development]]
[[Category:Add-on development]]

Revision as of 15:05, 19 November 2014

Service addons will be automatically started when XBMC starts. These addons must offer the xbmc.service extension point. You can specify when you want your addon to start, using the start tag. If it's isn't here, your addon will automatically start after user login. If you want it to start on XBMC startup, you need to set the start tag to startup. 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"
       version="1.0.0"
       provider-name="">
  <requires>
    <import addon="xbmc.python" version="2.1.0"/>
  </requires>
  <extension point="xbmc.service" library="service.py" start="login">
  </extension>
  <extension point="xbmc.addon.metadata">
    <platform>all</platform>
    <summary lang="en"></summary>
  </extension>
</addon>

If your addon is meant to be run while XBMC is running, you need to periodically check if XBMC is exiting. The addon is responsible for terminating when XBMC 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().


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


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

import time
import xbmc

if __name__ == '__main__':
    monitor = xbmc.Monitor()
    
    while not monitor.waitForAbort(10):
        xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGDEBUG)