XBMC Add-on - testing result of Excecutebuiltin
#1
I've written an add-on for XBMC (under RaspBMC) that runs at Start-up; the python code checks for the existence of a USB memory stick, and then executes a builtin function. Can I test (in the python script) the result of the builtin function?

My python code line looks like this: xbmc.executebuiltin(PlayMediaCommand)
where the PlayMediaCommand variable looks something like "PlayMedia (myfoldername,isdir)"

When I have media files, they play OK. But how can I find out (in python) whether that actually worked? For instance, if there were no media files in the folder/directory, nothing would play; but how can I check that in python, so that I can then do something else instead?

All help gratefully received.
Reply
#2
Assuming that calling xbmc.executebuiltin doesn't return a sucess/failure, off the top of my head I'd call the JSON rpc with "Player.GetActivePlayers". If you get back a null string, then nothing is playing.

Dunno how to do that in python, but I have a bash script running on my server, that cycles through connected clients and lists what they are playing (so I can keep an eye on my kids). My code probably isn't the cleanest, but it works, and to do it in bash is like this.
Code:
PlayerId=$(curl -s --data-binary '{ "jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": "mybash"}' -H 'content-type: application/json;' http://$xbmcAddress:9001/jsonrpc)
PlayerId=(`echo "$PlayerId" | grep "result"`)
PlayerType=$( echo "$PlayerId" | cut -d',' -f4)
PlayerType=$(echo "$PlayerType" | cut -d':' -f2 | sed 's/"//'g | sed 's/}//g' | sed 's/]//'g )
#echo "Player type is : $PlayerType"
PlayerId=$(echo "$PlayerId" | cut -d'{' -f3 | sed 's/[^0-9]*//g')
#echo "Player ID is : $PlayerId"

if [ "$PlayerType" = "" ]
    then
    echo "Not playing anything"
    exit 0
fi


if [ "$PlayerType" = "audio" ]
then

From the little python I do know, it should be much easier to get the player ID and type with it than the above.

There's probably better ways to do it, it just sprang to mind because I've already got something checking for playing content (even though it's external to XBMC).
Learning Linux the hard way !!
Reply
#3
black_eagle, thanks for your reply. I'm sorry I haven't responded sooner - I've been working too hard, and not had time to go back to XBMC set-up. I appreciate your suggestion, though I confess I'm going to have to do a bit more education before I can claim to understand it, and take it further. I have a sneaky suspicion that the Raspbmc distro doesn't include bash. I'll check when I get back to my test-bed.
I appreciate you taking your time to reply, and I'll advise how I get on, when the time comes.
Reply

Logout Mark Read Team Forum Stats Members Help
XBMC Add-on - testing result of Excecutebuiltin0