Service add-ons: Difference between revisions
(add gotham example) |
No edit summary |
||
Line 20: | Line 20: | ||
</source> | </source> | ||
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 | 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 <code>abortRequested()</code> method. To wait for this event instead, call '''waitForAbort()'''. | ||
Example service that prints "hello addon!" every 10 second until XBMC exits: | Example service that prints "hello addon!" every 10 second until XBMC exits: | ||
Line 31: | Line 31: | ||
monitor = xbmc.Monitor() | monitor = xbmc.Monitor() | ||
while | while True: | ||
# Sleep/wait for abort for 10 seconds | |||
if monitor.waitForAbort(10): | |||
# Abort was requested while waiting. We should exit | |||
break | |||
xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGDEBUG) | xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGDEBUG) | ||
</source> | </source> | ||
== Gotham an earlier == | |||
''abortRequested()'' and ''waitForAbort()'' are new in Helix. In Gotham, use ''xbmc.sleep'' and check the ''xbmc.abortRequested'' attribute periodically. | |||
Example: | |||
<source lang="python"> | <source lang="python"> | ||
import xbmc | import xbmc | ||
if __name__ == '__main__': | if __name__ == '__main__': | ||
while | while True: | ||
some code | if xbmc.abortRequested: | ||
break | |||
# some code | |||
xbmc.sleep(500) | xbmc.sleep(500) | ||
</source> | </source> |
Revision as of 13:57, 14 December 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().
Example service that prints "hello addon!" every 10 second until XBMC exits:
import time import xbmc if __name__ == '__main__': monitor = xbmc.Monitor() while True: # Sleep/wait for abort for 10 seconds if monitor.waitForAbort(10): # Abort was requested while waiting. We should exit break xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGDEBUG)
Gotham an earlier
abortRequested() and waitForAbort() are new in Helix. In Gotham, use xbmc.sleep and check the xbmc.abortRequested attribute periodically.
Example:
import xbmc if __name__ == '__main__': while True: if xbmc.abortRequested: break # some code xbmc.sleep(500)