User Tools

Site Tools


doc:appunti:software:kodi_addon_disable_screensaver

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:software:kodi_addon_disable_screensaver [2023/05/20 18:54] – [JSON RPC] niccolodoc:appunti:software:kodi_addon_disable_screensaver [2023/05/20 21:29] (current) – [How to disable the screensaver from a Kodi add-on] niccolo
Line 1: Line 1:
-====== How to disable the screensaver into a Kodi add-on ======+====== How to disable the screensaver from a Kodi add-on ======
  
 I wrote a Kodi **[[https://kodi.wiki/view/HOW-TO:Script_addon|script add-on]]** (that is different from a [[https://kodi.wiki/view/Audio-video_add-on_tutorial|audio/video plugin add-on]]) to play a special slideshow from a directory containing images. The peculiarity of my script is that it performs a resize and crop of images on the fly, following the instructions of a playlist. I wrote a Kodi **[[https://kodi.wiki/view/HOW-TO:Script_addon|script add-on]]** (that is different from a [[https://kodi.wiki/view/Audio-video_add-on_tutorial|audio/video plugin add-on]]) to play a special slideshow from a directory containing images. The peculiarity of my script is that it performs a resize and crop of images on the fly, following the instructions of a playlist.
Line 5: Line 5:
 Writing the add-on I faced the problem to disable the screensaver during image playback. It turned out that on the internet you find several examples, which are sometimes confusing and not working. In this page I hope to explain all the possibilities offered by **Kodi 19 Matrix**. Writing the add-on I faced the problem to disable the screensaver during image playback. It turned out that on the internet you find several examples, which are sometimes confusing and not working. In this page I hope to explain all the possibilities offered by **Kodi 19 Matrix**.
  
-===== JSON RPC =====+Before Kodi 19 Matrix the only way to disable the screensaver was to change settings via the JSON RPC API, starting with version 19 it is possible (and simpler) to call a built-in function. 
 + 
 +===== Using JSON RPC =====
  
 There are several Kodi settings related to the screensaver, screen dimming and power saving. From the Python code of the add-on it is possible to read each setting and change its value. Generally it is necessary to read the current settings when the add-on is started, change the values if required and restore the previous values on add-on exit. There are several Kodi settings related to the screensaver, screen dimming and power saving. From the Python code of the add-on it is possible to read each setting and change its value. Generally it is necessary to read the current settings when the add-on is started, change the values if required and restore the previous values on add-on exit.
  
-Into the add-on code you can use the Python function **xbmc.executeJSONRPC()** to communicate with Kodi itself, using the [[https://kodi.wiki/view/JSON-RPC_API|JSON RPC API]]. You may need to save/change/restore several settings to effectively disable the screensaver. In my experience the most important are **powermanagement.displaysoff** and **screensaver.mode**.+Into the add-on code you can use the Python function **xbmc.executeJSONRPC()** to communicate with Kodi itself, using the [[https://kodi.wiki/view/JSON-RPC_API|JSON RPC API]]. You may need to save/change/restore several settings to effectively disable the screensaver. In my experience the most important are **powermanagement.displaysoff** and **screensaver.mode**: setting the first to **zero** and the second to the **empty string** should turn off any screensaver in Kodi.
  
-^ powermanagement.displaysoff +^ powermanagement.displaysoff  | **[int]** Time in minutes to wait before turning off the display. When set to zero the function is disabled. This setting can be enabled even if no screensaver is active.  | 
-^ screensaver.mode             | +^ screensaver.mode             | **[str]** Name of the active screensaver. An empty string means to active screensaver.  
-^ screensaver.time             | +^ screensaver.time             | **[int]** Time in minutes before starting the screensaver. This timer is indipendent from //powermanagement.displaysoff//.  
-^ screensaver.usedimonpause    |+^ screensaver.usedimonpause    | **[bool]** Dim the display when media is paused.  |
  
 <code python> <code python>
-    command = { +# Read current value of powermanagement.displaysoff setting. 
-        'jsonrpc': '2.0', 'id': 0, 'method': 'Settings.setSettingValue', +command = { 
-        'params': { 'setting': 'screensaver.usedimonpause', 'value': dim+    'jsonrpc': '2.0', 'id': 0, 'method': 'Settings.getSettingValue', 
-    +    'params': { 'setting': 'powermanagement.displaysoff'
-    json_rpc = json.loads(xbmc.executeJSONRPC(json.dumps(command))) +
-    result = json_rpc['result']+json_rpc = json.loads(xbmc.executeJSONRPC(json.dumps(command))) 
 +self.saved_displaysoff = json_rpc['result']['value'
 +# Set powermanagement.displaysoff to zero, to disable display power off. 
 +command = { 
 +    'jsonrpc': '2.0', 'id': 0, 'method': 'Settings.setSettingValue', 
 +    'params': { 'setting': 'powermanagement.displaysoff', 'value': 0
 +
 +json_rpc = json.loads(xbmc.executeJSONRPC(json.dumps(command))) 
 + 
 +# ... Add-on executes its job... 
 + 
 +# Restore powermanagement.displaysoff to the saved value. 
 +command 
 +    'jsonrpc': '2.0', 'id': 0, 'method': 'Settings.setSettingValue', 
 +    'params': { 'setting': 'powermanagement.displaysoff', 'value': self.saved_displaysoff} 
 +
 +json_rpc = json.loads(xbmc.executeJSONRPC(json.dumps(command))) 
 +</code> 
 +===== Using a built-in function ===== 
 + 
 +There is another way to disable the screensaver in Kodi: it is a [[https://xbmc.github.io/docs.kodi.tv/master/kodi-base/d0/d3e/page__list_of_built_in_functions.html#built_in_functions_15|built-in system function]] called **InhibitScreensaver()** that was added in Kodi 19 Matrix. To call a built-in function there is the Python **xbmc.executebuiltin()**: 
 + 
 +<code python> 
 +# Prevent any screensaver to start. 
 +xbmc.executebuiltin('InhibitScreensaver(true)'
 + 
 +# ... Add-on executes its job... 
 + 
 +# Restore the screensaver default behaviour. 
 +xbmc.executebuiltin('InhibitScreensaver(false)')
 </code> </code>
-===== System settings ===== 
  
 ===== Web References ===== ===== Web References =====
Line 31: Line 61:
   * **[[https://forum.kodi.tv/showthread.php?tid=354784|Toggle Screensaver on/off through JSON-RPC?]]**   * **[[https://forum.kodi.tv/showthread.php?tid=354784|Toggle Screensaver on/off through JSON-RPC?]]**
   * **[[https://kodi.wiki/view/JSON-RPC_API|Kodi JSON RPC API]]**   * **[[https://kodi.wiki/view/JSON-RPC_API|Kodi JSON RPC API]]**
 +  * **[[https://xbmc.github.io/docs.kodi.tv/master/kodi-base/index.html|Kodi Documentation]]** (current)
 +  * **[[https://codedocs.xyz/w3tech/xodi/index.html|Kodi Documentation]]** (snapshot of version 19.0)
  
doc/appunti/software/kodi_addon_disable_screensaver.1684601659.txt.gz · Last modified: 2023/05/20 18:54 by niccolo