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

[pygame] [newbie] Sound within pygame



I'm writing a simple wxPython application that needs to play some sound. I
thought I would use pygame as it seems the most supported of methods for
getting sound.

The simple sound-test program I have written [1] was taken from a tutorial
on how to write pygame applications. However, it doesn't play anything in
windows or linux. I have a directory named data with a a.wav file in but
nothing seems to happen.

Am I missing something?

TIA.

Adam

[1]
import os, pygame
from pygame.locals import *

pygame.init()
def load_sound(name):
    class NoneSound:
        def play(self): pass
    if not pygame.mixer or not pygame.mixer.get_init():
        return NoneSound()
    fullname = os.path.join('data', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.error, message:
        print 'Cannot load sound:', fullname
        raise SystemExit, message
    return sound

mysound = load_sound('a.wav')
mysound.play()