Perhaps the game is also in Python, that is, do not use os.startfile , use some Python library to play the file.
I recently wrote such a library / module, the musicplayer module ( in PyPI ). Here is a simple demo player that you can easily extend for your shuffle code.
Just do easy_install musicplayer . Then, here is a sample 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]
source share