[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] loading ogg or mp3 files



Jacques Guignot wrote:
It's very easy, with pygame, to load a wav file, but I didn't find in the doc, a way to load a more compressed format, such as ogg or mp3 for instance... Of course, it is possible to convert 'on the fly' to wav format, and load the newly created wav file, but it's not clean, and very slow...

I was working on music code just now! Here's a very simple example: ##<http://www.xepher.net/~kschnee/music.txt> import os, sys, pygame

## A simple demo of how to play music in Python/Pygame.
## By Kris Schnee.

print "Running music demo. Hit Enter to quit."

## Pick an MP3 or MIDI-format music file in this directory.
MUSICFILE = "sa-tails.mp3"

pygame.mixer.init()

pygame.mixer.music.load(MUSICFILE)
pygame.mixer.music.play()

raw_input("> ") ## Wait for user to hit Enter.

## DONE
pygame.mixer.music.stop()
pygame.mixer.quit()
print "Done."

## End example.


If you want, I can post music.py, a set of functions for working with music relatively easily.


Kris