2011-06-27 05:12:03 +00:00
|
|
|
"""
|
|
|
|
Basic Sound Playback
|
2011-06-27 07:44:59 +00:00
|
|
|
++++++++++++++++++++
|
2011-06-27 05:12:03 +00:00
|
|
|
This script shows how to use the classes: :class:`Device`, :class:`Factory` and
|
|
|
|
:class:`Handle`.
|
|
|
|
"""
|
|
|
|
import aud
|
|
|
|
|
|
|
|
device = aud.device()
|
|
|
|
# load sound file (it can be a video file with audio)
|
|
|
|
factory = aud.Factory('music.ogg')
|
|
|
|
|
|
|
|
# play the audio, this return a handle to control play/pause
|
2011-10-02 18:00:06 +00:00
|
|
|
handle = device.play(factory)
|
2011-06-27 05:12:03 +00:00
|
|
|
# if the audio is not too big and will be used often you can buffer it
|
2011-10-02 18:00:06 +00:00
|
|
|
factory_buffered = aud.Factory.buffer(factory)
|
|
|
|
handle_buffered = device.play(factory_buffered)
|
2011-06-27 05:12:03 +00:00
|
|
|
|
|
|
|
# stop the sounds (otherwise they play until their ends)
|
|
|
|
handle.stop()
|
|
|
|
handle_buffered.stop()
|