Wt 3.1.10
|
Utility class to play a sound. More...
#include <Wt/WSound>
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 url played by this class. | |
int | loops () const |
Returns the configured number of loops for this object. | |
void | setLoops (int number) |
Sets the amount of times the sound has to be played for every invocation of play() | |
void | play () |
Start asynchronous playback of the sound. | |
void | stop () |
Stops playback of the sound. |
Utility class to play a sound.
This class provides a way to play a sound asynchonously (if the browser supports this). It is intended as a simple way to play event sounds (not quite for a media center).
The current implementation uses Adobe Flash to play sounds in the web browser. Future releases may use the HTML5 tags to play audio in the browser. The appropriate file formats depend on the Flash player or the browser support, but MP3 or WAV are most widely supported.
This class uses resourcesURL"WtSoundManager.swf", a flash object, and resourcesURL"swfobject.js", a companion JavaScript library, which are both distributed with Wt in the resources folder, see deployment and resources.
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);
Wt::WSound::~WSound | ( | ) |
Destructor.
The destructor calls stop() and unloads the sound object.
int Wt::WSound::loops | ( | ) | const |
Returns the configured number of loops for this object.
When play() is called, the sound will be played for this amount of loops.
void Wt::WSound::play | ( | ) |
Start asynchronous playback of the sound.
This method returns immediately. It will cause the song to be played for the configured amount of loops.
The behavior of play() when a sound is already playing depends on the method to play songs in the browser (Flash/HTML5). It may be mixed with an already playing instance, or replace the previous instance. 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 played for every invocation of play()
The behavior is undefined for negative loop numbers.
void Wt::WSound::stop | ( | ) |
Stops playback of the sound.
This method returns immediately. It causes the playback of this WSound to be terminated.