Stopping and starting a complex playlist
#1
I have built an application that will play six hours of mixed media for an old peoples home. Included are videos; music with moving images backgrounds; and quiet times with no sound.

The script for this is based upon some 20 playlists, example entries are:

xbmc.executebuiltin("PlayMedia(/home/pi/.xbmc/userdata/playlists/video/Sect2_vid1.m3u)")
time.sleep(437)
xbmc.executebuiltin("PlayMedia(/home/pi/.xbmc/userdata/playlists/music/Sect2_mus1.m3u)")
xbmc.executebuiltin("SlideShow(/media/TRANS_SD_B/Interlude,recursive,random)")
time.sleep(353)

To start the script I have a line in Home.xml

<onclick>XBMC.RunScript(special://skin/scripts/leonie_script.py)</onclick>

The difficulty is that there seems no easy way of stopping the script short of turning off the Raspberry Pi. Even if I turn off a video that is running, when the next xbmc.executebuiltin comes up, the next item starts running. The script is still running in the background.

I have mapped the '0' button on my remote to 'StopScript', thinking I could have a 'while not StopScript' statement at the top of my leonie_script.py. This is aimed at putting leonie_script.py in a loop waiting for something to happen, while playing the content.

I would very much appreciate assistance with suitable python code to stop the complex leonie_script.py script. I can't find anything after several hours of looking. The skin is Confluence.
Reply
#2
A quick hack/fix would be for your "StopScript" to create a control file (eg. /tmp/stop.file) which you test the existence of before every step in your leonie_script.py - if the file exists, you exit. Eg:

Code:
def checkabort():
  if os.path.exists("/tmp/stop.file"):
    os.remove("/tmp/stop.file")
    sys.exit(0)

def checksleep(timeout):
  while timeout >= 0:
    checkabort()
    timeout = timeout - 1
    time.sleep(1.0)

xbmc.executebuiltin("PlayMedia(/home/pi/.xbmc/userdata/playlists/video/Sect2_vid1.m3u)")
checksleep(437)
xbmc.executebuiltin("PlayMedia(/home/pi/.xbmc/userdata/playlists/music/Sect2_mus1.m3u)")
checkabort()
xbmc.executebuiltin("SlideShow(/media/TRANS_SD_B/Interlude,recursive,random)")
checksleep(353)  # Is this one needed?

In your 'StopScript', simply create the file /tmp/stop.file, then stop the current player.

I'm guessing that the various xbmc.executebuiltin() calls will block until they finish, in which case execution of the leonie_script.py only continues once the player is stopped, and the script should then exit if/when it detects the presence of the "stop.file". If the "StopScript" is executed while leonie_script.py is sleeping, leonie_script.py will exit as soon as it wakes up from sleep. You could of course implement a sleep that wakes every 1 second and checks for the abort, I've added that above too, so now leonie_script.py should execute more or less immediately after the StopScript is called.

Edit: Or are the sleeps acting as the "blocks" until the preceding item has completed playing (ie. the first playlist Sect2_vid1.m3u has a duration of 437 seconds?) If so it shouldn't really matter, although you could simplify/streamline the workflow further:
Code:
def checkabort():
  if os.path.exists("/tmp/stop.file"):
    os.remove("/tmp/stop.file")
    sys.exit(0)

def checksleep(timeout):
  while timeout >= 0:
    checkabort()
    timeout = timeout - 1
    time.sleep(1.0)

def execute(play=None, slide=None, timeout=None):
  if play:
    xbmc.executebuiltin("PlayMedia(%s)" % play)
  if slide:
    xbmc.executebuiltin("SlideShow(%s)" % slide)
  if timeout:
    checksleep(timeout)

execute(play="/home/pi/.xbmc/userdata/playlists/video/Sect2_vid1.m3u", timeout=437)
execute(play="/home/pi/.xbmc/userdata/playlists/music/Sect2_mus1.m3u", slide="/media/TRANS_SD_B/Interlude,recursive,random", timeout=353)
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#3
Thanks Milhouse, I'll get to work on the hack.
Reply
#4
The suggested coding has now been incorporated and works fine, I have tested it over many days. Thanks Milhouse.
Reply

Logout Mark Read Team Forum Stats Members Help
Stopping and starting a complex playlist0