I got some time to play with this more, testing both on my Vista machine and
OS X 10.5.
with SDL_Mixer 1.2.8, ogg and mp3 and mid and mod all seem to be able to
load from a file or file-like object on my windows machine, so I think
Forrest is right about the level of support in SDL_Mixer 1.2.8
...but there were a few of issues...
1. if I try to call mixer.music.load again after having tried to play a song
from a file or file-like object, it hangs on the loading
2. the pygame examples/data/house_lo.mp3 plays silence when I try to play it
from a filename, but loading from a file or file-like object I get an
exception of unrecognized file type (which must be the ID3 tag thing Forrest
called out earlier?)
3. the mid file claims to load but plays nothing, regardless of how I load
it
2 and 3 may be issues with the file, and are not likely to be problem's with
loading from rw_objects at all, but issue 1 (hanging on trying to load a
different piece of music after loading from a file-like object) seems like a
serious problem that is the responsibility of the loading from rwobject code
to fix.
I have no idea what the cause of it is - from the prints for a file-like
object loader, it seems to do the exact same sequence of seek, tell and read
as when it doesn't hang, except that the load call simply doesn't return. I
had to rebuild pygame with the mixer version check changed of course, but It
happens for both my Leopard and Vista machines, so I don't think it's
anything about my builds in particular.
here's the code I was running (with Forrest's sound files and the files from
pygame)
-------------------------
import pygame
import time
pygame.init()
pygame.display.set_mode((320,200))
pygame.event.pump()
files = ["sound.ogg", "sound.mp3", "sound.mod", "sound.mid", "house_lo.ogg",
"house_lo.mp3"]
class file_like_wrapper():
def __init__(self, fname):
self.my_fname = fname
self.my_file = file(fname, "rb")
def read(self, size=None):
print self.my_fname,"read", size
if size != None:
return self.my_file.read(size)
else:
return self.my_file.read()
def seek(self, offset, whence):
print self.my_fname,"seek",offset, whence
return self.my_file.seek(offset, whence)
def tell(self):
tell_pos = self.my_file.tell()
print self.my_fname,"tell", tell_pos
return tell_pos
def close(self):
print self.my_fname,"close"
return self.my_file.close()
for filename in files:
print "loading",filename,"..."
print "from filename",
sound = pygame.mixer.music.load(filename)
print "loaded!"
pygame.mixer.music.play()
print "playing!"
time.sleep(3)
pygame.event.pump()
pygame.mixer.music.stop()
print "loading from file-like object",
sound = pygame.mixer.music.load(file_like_wrapper(filename))
print "loaded!"
pygame.mixer.music.play()
print "playing!"
time.sleep(3)
pygame.event.pump()
print "done playing!"
pygame.mixer.music.stop()
print "loading from file object",
sound = pygame.mixer.music.load(file(filename, "rb"))
print "loaded!"
pygame.mixer.music.play()
print "playing!"
time.sleep(3)
pygame.event.pump()
print "done playing!"
pygame.mixer.music.stop()