So i have the code:
import glob,os
import random
path = \'C:\\\\Music\\\\\'
aw=[]
for infile in glob.glob( os.path.join(path,\'*.mp3\') ):
libr = infil
Maybe do the playing also within Python, i.e. don't use os.startfile, use some Python library to play the file.
I have recently written such a library/module, the musicplayer module (on PyPI). Here is a simple demo player which you can easily extend for your shuffle code.
Just do easy_install musicplayer. Then, here is some example code to get the length:
class Song:
def __init__(self, fn):
self.f = open(fn)
def readPacket(self, bufSize):
return self.f.read(bufSize)
def seekRaw(self, offset, whence):
self.f.seek(offset, whence)
return self.f.tell()
import musicplayer as mp
songLenViaMetadata = mp.getMetadata(Song(filename)).get("duration", None)
songLenViaAnalyzing = mp.calcReplayGain(Song(filename))[0]