Logo Search packages:      
Sourcecode: pythoncard version File versions  Download package

sound.py

"""
__version__ = "$Revision: 1.6 $"
__date__ = "$Date: 2004/04/14 00:17:43 $"
"""

import wx
import sndhdr

00009 class Sound:
    """
    Feeble beginnings of a class for playing sounds.
    The goal is to be able to provide a filename and then be able
    to play the sound without worrying about sound formats or particular
    OS capabilities. I haven't investigated the Python Standard Libraries
    much yet.
    """
    
    def __init__(self, filename) :
        self._filename = filename
        self._sndType = sndhdr.what(filename)
        if self._sndType:
            self._sndType = self._sndType[0]
        if self._sndType in ['wav']:
            try:
                self._sound = wx.Sound(filename)    # support resources?
            except:
                self._sndType = None
        else:
            self._sndType = None
        if not self._sndType:
            raise

    def play(self, async=True, looped=False) :
        if self._sndType:
            if async:
                if looped:
                    flags = wx.SOUND_ASYNC | wx.SOUND_LOOP
                else:
                    flags = wx.SOUND_ASYNC
            else:
                flags = wx.SOUND_SYNC
            self._sound.Play(flags)

    def stop(self):
        if self._sndType:
            self._sound.Stop()

Generated by  Doxygen 1.6.0   Back to index