Wt: Wt::WSound Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
Wt::WSound Class Reference

A value class to play a sound effect. More...

`#include <Wt/WSound>`

Inheritance diagram for Wt::WSound:
[legend]

List of all members.

## Public Member Functions
| WSound (const std::string &url, WObject *parent=0)
| Constructs a sound object that will play the given URL.
| ~WSound ()
| Destructor.
const std::string & | url () const
| Returns the sound url.
void | setLoops (int number)
| Sets the amount of times the sound has to be repeated.
int | loops () const
| Returns the configured number of repeats.
void | play ()
| Start asynchronous playback of the sound.
void | stop ()
| Stops playback of the sound.

## Detailed Description

A value class to play a sound effect.

This class provides a way to play an MP3 sound asynchonously (if the browser supports this). It is intended as a simple way to play event sounds (not quite for a media center).

This class uses a WMediaPlayer to play the sound (using HTML <audio> or a flash player).

Usage example:

     WSound *s = new WSound("djing.mp3", parent);
     s->setLoops(3);
     s->play();
     playButton->clicked().connect(s, &WSound::play);
     stopButton->clicked().connect(s, &WSound::stop);

## Constructor & Destructor Documentation

Wt::WSound::WSound | ( | const std::string & | url,
|  | WObject * | parent = `0`
| ) |  |

Constructs a sound object that will play the given URL.

Note:
  As of Wt 3.1.10, the `url` must specify an MP3 file.

Wt::WSound::~WSound | ( |  | ) |

Destructor.

Deleting a sound also stops it (if it was playing).

## Member Function Documentation

int Wt::WSound::loops | ( |  | ) | const

Returns the configured number of repeats.

setLoops()

void Wt::WSound::play | ( |  | ) |

Start asynchronous playback of the sound.

This method returns immediately. It will cause the sound to be played for the configured amount of loops().

The behavior of play() when a sound is already playing is undefind: it may be intermixed, sequentially queued, or a current playing sound may be stopped. It is recommended to call stop() before play() if you want to avoid mixing multiple instances of a single WSound object.

void Wt::WSound::setLoops | ( | int | number | ) |

Sets the amount of times the sound has to be repeated.

A call to play() will play the sound `number` of times. The default value is 1 (no repeats).

void Wt::WSound::stop | ( |  | ) |

Stops playback of the sound.

This method returns immediately. It causes the current playback (if any) of the sound to be stopped.

const std::string & Wt::WSound::url | ( |  | ) | const

Returns the sound url.

See also:
  WSound()

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator