aud.py 624 B

1234567891011121314151617181920212223
  1. """
  2. Basic Sound Playback
  3. ++++++++++++++++++++
  4. This script shows how to use the classes: :class:`Device`, :class:`Factory` and
  5. :class:`Handle`.
  6. """
  7. import aud
  8. device = aud.device()
  9. # load sound file (it can be a video file with audio)
  10. factory = aud.Factory('music.ogg')
  11. # play the audio, this return a handle to control play/pause
  12. handle = device.play(factory)
  13. # if the audio is not too big and will be used often you can buffer it
  14. factory_buffered = aud.Factory.buffer(factory)
  15. handle_buffered = device.play(factory_buffered)
  16. # stop the sounds (otherwise they play until their ends)
  17. handle.stop()
  18. handle_buffered.stop()