Background music revisited
#1
I've been following a thread (http://forum.xbmc.org/showthread.php?tid=36859) that tells me how to get background music. If you look at that thread you will see that you have to create two scripts with py extensions (default.py and autoexec.py) It was fairly explicit about where to place the autoexe.py file (in the userdata folder) but no indication where to put the default.py file. I've tried putting it in the userdata folder with the autoexe.py file but nothing seems to happen. I've opened the default.py file and given the address of the m3u that I created (C:\Users\Pan2\AppData\Roaming\XBMC\userdata\playlists\music\playlist.m3u). I've asked twice in that thread for help with this without answer. It may be that it's just an old thread that no one looks at any more so I'm appealing to get help. Help? Smile
Reply
#2
If your default.py is invoked by your autoexec.py, then specify the path (location) of the former in the latter.
Reply
#3
Do you mean for example:

#execute targeted script at startup.
import xbmc
xbmc.executescript C:\Users\Pan2\AppData\Roaming\XBMC\userdata\default.py


or is my syntax incorrect?
Reply
#4
See topic "3 Using Built-in Functions from python" here: http://wiki.xbmc.org/index.php?title=Built-in_scripting
Reply
#5
I did as you said but it made no difference other than me trying different syntax none of which worked. Is there anything fundamentally wrong with this script?, I mean, that is the path to the script. Do I have to actually install some sort of python plug-in first?

xbmc.executescript('C:\Users\Pan2\AppData\Roaming\XBMC\userdata\default.py')

with and without the inverted commas
I'm not a programmer so going to look at python scripting is a huge learning curve for me Confused
Reply
#6
I provided that link so you can copy the example provided, which is:
Code:
executebuiltin('XBMC.RunScript(Q:\Scripts\myscript.py)')
So your autoexec.py script would be:
Code:
import xbmc
executebuiltin('XBMC.RunScript(C:\Users\Pan2\AppData\Roaming\XBMC\userdata\default.py)')

Also:
  • Have you already tested your default.py script to be sure it runs without errors and does what you had intended it to do? No point in starting it via autoexec.py until you know it (default.py) is working properly.
  • If you still have problems, check your debug log (wiki) to see where it's failing. (NOTE: If you want others to review your log, upload it to www.xbmclogs.com and post just the assigned URL to it here. Do not paste log contents directly in your post).
Reply
#7
Will do. Still nothing, I looked at the log and there was no reference to the default.py. There seems to be only one thing you can do to the default.py and that is the address of the media. Maybe that's where I'm stuffing up. Here is the top part of the default.py:

media="C:\Users\Pan2\AppData\Roaming\XBMC\userdata\playlists\music\playlist.m3u"
# This can be a playlist, music, or video file or an Url.
playercontrol1="RandomOn"
playercontrol2=""
# "RandomOn", "RandomOff", "RepeatOne", "RepeatAll", "Partymode(music)", "Partymode(path to .xsp file)"
sfx=False
# True or False | Note that there are no quotes around True or False
# media needs to be a path to a .wav file if this is true
randomplaylist=True
# Set randomplaylist to True and playercontrol1 to RandomOn to start the playlist
# on the second (random) song. Otherwise set this to False.
volume="40"
# This is a percent between 0 and 100. 0 is mute and 100 is max volume.

I tested the m3u with vlc player and it works fine
Reply
#8
That snippet of your script doesn't really do anything other than define some variables. Is there more to it? What's it supposed to do?
Reply
#9
It's supposed to randomly choose a track from a playlist and play it until an action such as a movie starts or you play some music etc. Once that action has ceased, it's supposed to start up again.

Here is my complete default.py script:

media="C:\Users\Pan2\AppData\Roaming\XBMC\userdata\playlists\music\playlist.m3u"
# This can be a playlist, music, or video file or an Url.
playercontrol1="RandomOn"
playercontrol2=""
# "RandomOn", "RandomOff", "RepeatOne", "RepeatAll", "Partymode(music)", "Partymode(path to .xsp file)"
sfx=False
# True or False | Note that there are no quotes around True or False
# media needs to be a path to a .wav file if this is true
randomplaylist=True
# Set randomplaylist to True and playercontrol1 to RandomOn to start the playlist
# on the second (random) song. Otherwise set this to False.
volume="40"
# This is a percent between 0 and 100. 0 is mute and 100 is max volume.


####################################
#Don't mess with anything down here#
#unless you know what you're doing #
####################################

import nt,xbmc,xbmcgui
from os import path

xbmc.executehttpapi('SetResponseFormat&parameter=WebHeader;False;WebFooter;False')
# if (media!="" and not path.isfile(media)):
# xbmcgui.Dialog().ok('Invalid Path','Path to media not found')

y=1
while y==1:
rawResponse=xbmc.executehttpapi('getcurrentlyplaying')
if rawResponse=='<li>Filename:[Nothing Playing]':
xbmc.executebuiltin('SetVolume('+volume+')')
if(media==""):
if (playercontrol1=="Partymode(music)" or playercontrol2=="Partymode(music)"):
xbmc.executebuiltin('XBMC.PlayerControl(Partymode(music))')
xbmc.sleep(5000)
elif(sfx==True):
try:
xbmc.playSFX(media)
except:
xbmc.log('playSFX failed')
else:
xbmc.executebuiltin('XBMC.PlayMedia('+media+')')
if playercontrol1!="":
xbmc.executebuiltin('XBMC.PlayerControl('+playercontrol1+')')
if playercontrol2!="":
xbmc.executebuiltin('XBMC.PlayerControl('+playercontrol2+')')
if randomplaylist==True:
xbmc.executebuiltin('XBMC.PlayerControl(Next)')
xbmc.sleep(5000)
else:
xbmc.sleep(2000)


Look if this (me) is becoming too much of a distraction for you just say and I'll quit trying to do this. You most likely have far better things to do with your time. The only way I can see this getting resolved is if someone else goes through the process of creating a small playlist and trying to do it; then writing down all the steps they went through
Reply
#10
That script cannot work since it uses the now-defunct HTTP API (xbmc.executehttpapi).

You can use the following in your autoexec.py to play songs in random order from a playlist when XBMC starts:
Code:
import xbmc
xbmc.executebuiltin( "PlayMedia(C:\Users\Pan2\AppData\Roaming\XBMC\userdata\playlists\music\playlist.m3u)" )
xbmc.executebuiltin( "PlayerControl(RandomOn)" )
However, once you interrupt playback of the playlist (e.g., pressing Stop or playing some other media), it will not resume automatically.
Reply
#11
Well that looks pretty straight forward and I assume the default.py becomes redundant. Well I tried it and, you guessed it, silence Sad
Reply
#12
Are you sure your playlist path (location) is correct and that the playlist itself is valid? Music > Playlists > playlist.m3u > do you see songs listed and can you play them (with sound)?
Reply
#13
Yep, checked the playlist.m3u with VLC Player, also checked it's path. Then rechecked the autoexe.py as per your script which was just a copy and paste.

Then made sure of the location of the autoexe.py script:
C:\Users\Pan2\AppData\Roaming\XBMC\userdata
Reply
#14
(2013-04-05, 12:15)pan2 Wrote: Yep, checked the playlist.m3u with VLC Player, also checked it's path. Then rechecked the autoexe.py as per your script which was just a copy and paste.
Did you play the playlist with XBMC as well?

Quote:Then made sure of the location of the autoexe.py script:
C:\Users\Pan2\AppData\Roaming\XBMC\userdata
Don't know if it's just a typo here, but the filename must be autoexec.py
Also check your debug log to verify autoexec.py was invoked at startup.
Reply
#15
oops Smile all good now Smile Thanks for your help and patience artrafael.Hopefully I will be able to return the favour one day. My expertise is in photoshop, not a big deal in this forum unfortunately Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Background music revisited0