Android Detecting failure in ExecuteBuiltin
#1
I use an Android tablet as an alarm clock, with Tasker set to run Kodi at the alarm time. Kodi then uses the following script to start playing an Internet radio stream:

Code:
import xbmc
xbmc.executebuiltin("PlayMedia(/storage/emulated/0/Music/BBCRadio1.strm)")

This works just fine, but occasionally the stream will fail to play and this means the alarm doesn't go off and I sleep in. Is there a way to detect whether ExecuteBuiltin has failed? Looking at the C++ I see that PlayMedia returns false if the media fails to play, but is this passed to ExecuteBuiltin and does ExecuteBuiltin return a result that I can use to check if the stream played? If not, is there some other way to check if the stream is playing - an IsPlaying() function or something like that?
Reply
#2
you could do it like this:
Code:
import xbmc

xbmc.Player().play('/storage/emulated/0/Music/BBCRadio1.strm')
if xbmc.Player().isPlaying() == False:
    print 'playback failed'
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
ronie, thanks, that's the hint I needed.

The trouble is that when xbmc.Player().play() fails it displays a dialog saying "One or more items failed to play" and the script hangs until you click OK. Except of course that I don't see the dialog because I'm asleep :-)

However this works:

Code:
import time
import xbmc

src = '/storage/emulated/0/Music/BBCRadio4.strm'

print 'Autoexec: Playback starting'
xbmc.executebuiltin('PlayMedia(' + src + ')')
time.sleep(60)

if xbmc.Player().isPlaying() == False:
    print 'Autoexec: Playback failed, trying again'
    xbmc.executebuiltin('PlayMedia(' + src + ')')

ExecuteBuiltin runs the command asynchronously, so you need the sleep before checking the player status. That also explains why ExecuteBuiltin can't return the result of the PlayMedia command.
Reply

Logout Mark Read Team Forum Stats Members Help
Detecting failure in ExecuteBuiltin0