File: sound.py

package info (click to toggle)
oneisenough 0.40-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 616 kB
  • sloc: python: 697; makefile: 7; sh: 2
file content (19 lines) | stat: -rw-r--r-- 457 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import pygame
import os

sounds = {}

def play_sound(filename, volume = 1.0):
    snd = None
    if not sounds.has_key(filename):
        try:
            sound_path = os.path.join("sounds", filename)
            snd = sounds[filename] = pygame.mixer.Sound(sound_path)
        except:
            print "Error: Sound file not found."
            return;
    else:
        snd = sounds[filename]

    snd.set_volume(volume)
    snd.play()