Marcus von Appen wrote:
Found it. The code never reaches the part that handles file objects, since mixer.c:881,882 return an error if the object has no buffer interface:On, Tue Feb 19, 2008, Alistair Buxton wrote:I'm an oblivious idiot :-). A buffer method's already available in the current SVN tree. You can use pygame.Sound (your_buffer) safely, the buffer just has to match the mixer criteria. Due to the SDL_Mixer implementation however, the buffer will be copied, so a manipulation of the buffer object after creating the Sound will not have any impact on it.I'm looking at that code right now. It looks like it tries to copy it, and if it can't, it raises an exception. But then there is a block of code right after which would load it in place, but can not be reached currently, because the previous code returns on error. Correct? So I'm guessing this is already WIP by somebody :)The code should be fully functional. To which unreachable lines do you refer?
if (PyObject_AsReadBuffer (file, &buf, &buflen) == -1) return -1; The following changes to examples\sound.py confirm it. file = open(os.path.join('data', 'secosmic_lo.wav'), 'rb') try: sound = mixer.Sound(file) finally: file.close() Running the modified sound.py raises an exception: Traceback (most recent call last): File "sound.py", line 21, in <module> sound = mixer.Sound(file) TypeError: expected a readable buffer object -- Lenard Lindstrom <len-l@xxxxxxxxx>