Autoplay music when XBMC idle
#1
I don't know if I'm even supposed to post here since I'm not really a developer.

I would like to create a script that auto plays a music folder when xbmc is idle and no other media is playing.

I found a thread with the same attempt here: http://forum.xbmc.org/showthread.php?tid=36859&page=2

I then realized that this isn't gonna work with Frodo since it doesn't use the autoexec.py script anymore, so I wrote an addon.xml file instead (code: http://pastebin.com/NgWhv7FR ) and placed that in a folder I created inside the xbmc addon folder.

I used "claimui"s revised script for the default.py code from the forum post above, only modified the filepath for the media. Code can be found here: http://pastebin.com/Jj6LUGXH

I have tried some different modification of the code but I always seem to end up with the following error in the xbmc.log: http://pastebin.com/9utXcVU0

Would be really grateful if someone could guide me on whats going on here..


thanks!
Reply
#2
Indentation is important in python. You commented out the opening line of the while() loop, which leaves the next if statement indented for no reason. You need that while() loop to keep things running.

There are a other things that have changed since that script was written, but you're on the right track. Here's what I suggest:
1. Make it a service addon
2. Add a setting to select a playlist
3. Grab the playlist from the setting
Reply
#3
Thanks for your input.

I actually commented out the while loop during testing, and posted the wrong code to pastebin. It seems that no matter what I do I get the same error in the log.

Here's a new paste with only the media path edited: http://pastebin.com/rq8HsySV

Here's the xbmc.log output: http://pastebin.com/eZ0sdPfi


I'll do some reading on making it a service addon instead, will post my results/headaches here
Reply
#4
Ahhh, ok. There is no space on the first line (media="c:\\1.mp3"), then there is a space before each line after that. Python interprets this as an indent and dies when it tries to make 'playercontrol1="RandomOn"' (the first non-comment) part of a code block that doesn't exist.

Solution:
Remove one space from every line except the first.

Also, in the future, avoid posting log snippets to the forum bc it makes it harder for people searching for working code. Instead, link them on pastebin or a similar service, just like your did the code snippets
Reply
#5
Thank you! The script is working like it should now I think, need to do some more testing.

But if I want to autorun the script, is this the command i should use? xbmc.executebuiltin("script.bgmusic(something?)")
Reply
#6
That's the reason for converting it to a service addon =)

Have a look at this: http://wiki.xbmc.org/index.php?title=How...g_services
Reply
#7
Converted to service and works really nice now!

Here's how I'm using it. Thought it be fun to know. I bought a raspberry pi and a little amplifier (vma 2016), installed some speakers in the ceiling in the bathroom and was able to use UPNP to send music to the speakers, nice while showering. But then I thought it would be nice to have some bird/nature sounds always on at low volume when just using the bathroom for a short while, that's why I wanted this addon =)

Is it possible to add some code so that the service only is active between xx:xx o'clock and xx:xx o'clock? that would be awesome

Thanks for helping me getting this to work Bstrdsmkr, I really appreciate it

Heres the new code if someone needs it:

default.py: http://pastebin.com/hrA6KUPm
addon.xml: http://pastebin.com/aMC4fy50
Reply
#8
The more I thought about this, the more it seemed like a good exercise. I cleaned it up a bit and packaged it up into an addon (start and stop time included).

Grab it here: https://github.com/bstrdsmkr/service.bgmusic
Reply
#9
Nice work =)

Just installed and configured it. But I'm having muting issues. The playlist always seems to start muted, no matter what setting I use. Any idea why?
Reply
#10
Oops! Misplaced a set of ''. Should be fixed on github now
Reply
#11
Thanks, will try it out tomorrow and get back to you =)
Reply
#12
I'm still having muting issues :-S

uninstalled previous version, deleted the remaining files in the addon_data folder and installed new version (please update version number on github to avoid confusion) but still the same issue.

I can see that you added xbmc.log messages in the code, but they don't seem to be working properly since I can't find anything about BGMusic in the log. Other than these two issues I think the service is working fine if I just turn up the volume every time the playlist is being played =)
Reply
#13
herp, derp.

Since I forgot to bump the version number, xbmc just reinstalled the old version from xbmc\addons\packages\

Grab it from github again and you should be good. I've got it running as we speak and it's kicking in at the specified volume =)
Reply
#14
You da man Wink

Works great. Thanks Wink
Reply
#15
Thanks for this nice servis.
I have a problem how to start this servis,what I need music playlists or just mp3 song.
Thanks in advance.
Reply

Logout Mark Read Team Forum Stats Members Help
Autoplay music when XBMC idle2