#snd

import pygame
from pygame import *

import data

pygame.mixer.pre_init(11025, 8)



def init(dosound):
    if dosound:
        pygame.mixer.get_init()
    

class DummySound:
    def play(self, *args): pass
    def set_volume(self, *args): pass
    


def sound(name):
    if not pygame.mixer or not pygame.mixer.get_init():
    	return DummySound()
    
    fullname = data.find_file('sound', name)
    s = pygame.mixer.Sound(fullname)
    return s


def music(name, volume=1.0):
    if not pygame.mixer or pygame.mixer.get_init(): return 

    fullname = data.find_file('music', name)
    if not fullname:
    	raise IOError, "Cannot find image for "+name
    pygame.mixer.music.load(fullname)
    pygame.mixer.music.set_volume(volume)
    pygame.mixer.music.play()
    


