~ubuntu-branches/ubuntu/gutsy/pygame/gutsy

« back to all changes in this revision

Viewing changes to examples/sound.py

  • Committer: Bazaar Package Importer
  • Author(s): Ed Boraas
  • Date: 2002-02-20 06:39:24 UTC
  • Revision ID: james.westby@ubuntu.com-20020220063924-amlzj7tqkeods4eq
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""extremely simple demonstration playing a soundfile
 
4
and waiting for it to finish. you'll need the pygame.mixer
 
5
module for this to work. Note how in this simple example we
 
6
don't even bother loading all of the pygame package. Just
 
7
pick the mixer for sound and time for the delay function."""
 
8
 
 
9
import os.path
 
10
import pygame.mixer, pygame.time
 
11
mixer = pygame.mixer
 
12
time = pygame.time
 
13
 
 
14
#choose a desired audio format
 
15
mixer.init(11025) #raises exception on fail
 
16
 
 
17
 
 
18
#load the sound    
 
19
file = os.path.join('data', 'secosmic_lo.wav')
 
20
sound = mixer.Sound(file)
 
21
 
 
22
 
 
23
#start playing
 
24
print 'Playing Sound...'
 
25
channel = sound.play()
 
26
 
 
27
 
 
28
#poll until finished
 
29
while channel.get_busy(): #still playing
 
30
    print '  ...still going...'
 
31
    time.wait(1000)
 
32
print '...Finished'
 
33
 
 
34
 
 
35