Run another function in script after PlayMedia
#1
I'll apologize in advance. I'm a rank beginner at Kodi, with a question that's probably almost trivial to most readers. I'm in a bind to get a project out the door for a client, and my various searches haven't found an answer to this simple question.

I want to be able run run the PlayMedia built-in to play a video clip, and when it's done run the ScreenSaver built-in. This will be triggered via xbmc-send/kodi-send. I have two problems:

1) My current code is as follows, but the slide show doesn't wait for the video to complete.

import xbmc
xbmc.executebuiltin('XBMC.PlayMedia(some-video.mp4)', True)
xbmc.executebuiltin('XBMC.SlideShow(somedirectory/slideshow)')

If I comment out the last line the video plays, but otherwise I immediately see the slide show.

2) I'm not able to launch this via kodi-send using the following:

kodi-send "--action=XBMC.RunScript('/home/pi/.kodi/userdata/somescript.py')"

The only way I can get it to run at all (to make sure the code is OK) is to rename it to "autoexec.py" and watch it at start-up.

Background detail:
- I'm running on a Raspberry Pi under Raspian
- I need Raspian rather than, say OSMC, so I can run other applications like a custom web server
- I'm running Kodi version 14.2, because that's what was in the Raspian repository
- The regular screen-saver plug-ins don't seen to work well for my network environment (NFS directories automounted on demand -- they keep thinking it's empty because they didn't try to access a file or directory to trigger the automount), whereas using the ScreenSaver built-in works perfectly every time.

Can someone take pity on a rank beginner and set me on the right track? Do I need to dive into callbacks or whatever Kodi offers for a notification system, or is there a simple solution?

Thanks in advance for any help you can provide.
Reply
#2
This would probably be better in the Python development area, but I think I can help.

You need to put a loop test in to see if the video is done. It should look something like this:

Code:
import xbmc, time

xbmc.executebuiltin('XBMC.PlayMedia(some-video.mp4)', True)
while (xbmc.Player().isPlayingVideo() == True) and (not xbmc.abortRequested):
    time.sleep( 1 )
xbmc.executebuiltin('XBMC.SlideShow(somedirectory/slideshow)')

The sleep call is just so that you don't overwhelm the system with thousands of checks, and abortRequested will drop out of the loop and allow XBMC to quit. I didn't test any of this, but it's similar to code I use in one of my addons. Hope it helps.
Reply
#3
Agreed - moved to add-on development
|Banned add-ons (wiki)|Forum rules (wiki)|VPN policy (wiki)|First time user (wiki)|FAQs (wiki) Troubleshooting (wiki)|Add-ons (wiki)|Free content (wiki)|Debug Log (wiki)|

Kodi Blog Posts
Reply

Logout Mark Read Team Forum Stats Members Help
Run another function in script after PlayMedia0