Autoplay music for beginers
#1
i have been trying to work out how play random music when i start xbmc, using my music directory on my pc.

i have the latest build of xbmc 05/05 and i have downloaded the following script, which i attempted to edit.

Quote:'''
author: rune hammersland
version: 0.2

xbox media center comes with a script to play an mp3 file at startup
(startupmp3). this script will load a playlist if it exists, and if not,
traverse a directory and load all relevant music files. it is intended as a
replacement for startupmp3, and enables you to listen to a playlist, or all
music files in a given directory.
'''

import xbmc
import os

# ---------------------------------------- #
# "configuration"
# ---------------------------------------- #

# change this to your playlist.
playlist_file = 'f:\\media\\music\\playlist.m3u'
# dir to traverse if playlist does not exist. nb: no trailing slash.
music_dir = 'smb://domain\username:[email protected]/my music'
# shuffle playlist if this var equals 1.
shuffle_files = 1


# ---------------------------------------- #
# code
# ---------------------------------------- #

# function for adding files to playlist
def add_files(pl, dirname, names):
   for filename in names:
       if (os.path.isfile(dirname + "\\" + filename)):
           add = 0
           
           # check extension of file.
           if (filename[-4:] == ".mp3"): add = 1
           if (filename[-4:] == ".ogg"): add = 1
           if (filename[-4:] == ".wav"): add = 1
           if (filename[-5:] == ".flac"): add = 1
           
           # if file is to be added, do it.
           if (add == 1): pl.add(dirname + "\\" + filename)
       elif (os.path.isdir(dirname + "\\" + filename)):
           os.path.walk(dirname + "\\" + filename, add_files, pl)

# get music playlist from xbmc
plist = xbmc.playlist(0)
plist.clear()

# load playlist if it exists
if (os.path.isfile(playlist_file)):
   plist.load(playlist_file)
# else, find all available music
else:
   os.path.walk(music_dir, add_files, plist)

# do the shuffle!
if (shuffle_files == 1): plist.shuffle()

xbmc.player().play(plist)

please could someone guide me through the whole process, as i am realy unsure of what i'm doing wrong.

i think there needs to be another .py file called "autoexec", but where that goes and what should be in it i am not sure.

thanks in advance

ps i have read stuff on the forum but am still confused, so keep it simple please
Reply

Logout Mark Read Team Forum Stats Members Help
Autoplay music for beginers0