## wxSound

This class represents a short sound (loaded from Windows WAV file), that can be stored in memory and played. Currently this class is implemented on Windows and Unix (and uses either Open Sound System or Simple DirectMedia Layer).

Derived from

wxObject

Include files

<wx/sound.h>

Members

wxSound::wxSound
wxSound::~wxSound
wxSound::Create
wxSound::IsOk
wxSound::IsPlaying
wxSound::Play
wxSound::Stop

### wxSound::wxSound

wxSound()

Default constructor.

wxSound(const wxString& fileName, bool isResource = false)

Constructs a wave object from a file or resource. Call wxSound::IsOk to determine whether this succeeded.

Parameters

fileName

The filename or Windows resource.

isResource

`true` if fileName is a resource, `false` if it is a filename.

### wxSound::~wxSound

~wxSound()

Destroys the wxSound object.

### wxSound::Create

bool Create(const wxString& fileName, bool isResource = `false`)

Constructs a wave object from a file or resource.

Parameters

fileName

The filename or Windows resource.

isResource

`true` if fileName is a resource, `false` if it is a filename.

Return value

`true` if the call was successful, `false` otherwise.

### wxSound::IsOk

bool IsOk() const

Returns `true` if the object contains a successfully loaded file or resource, `false` otherwise.

### wxSound::IsPlaying

static bool IsPlaying() const

Returns `true` if a sound is played at the moment.

### wxSound::Play

bool Play(unsigned flags = wxSOUND_ASYNC) const

static bool Play(const wxString& filename, unsigned flags = wxSOUND_ASYNC)

Plays the sound file. If another sound is playing, it will be interrupted. Returns `true` on success, `false` otherwise.

The possible values for flags are:

wxSOUND_SYNC | `Play` will block and wait until the sound is replayed.
wxSOUND_ASYNC | Sound is played asynchronously, `Play` returns immediately
wxSOUND_ASYNC | wxSOUND_LOOP | Sound is played asynchronously and loops until another sound is played, wxSound::Stop is called or the program terminates.

The static form is shorthand for this code:

    wxSound(filename).Play(flags);

### wxSound::Stop

static void Stop()

If a sound is played, this function stops it.