Class WSound
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).
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addSource
(MediaEncoding encoding, WLink link) Adds a media source.int
getLoops()
Returns the configured number of repeats.getSource
(MediaEncoding encoding) Returns the media source.void
play()
Start asynchronous playback of the sound.void
setLoops
(int number) Sets the amount of times the sound has to be repeated.void
stop()
Stops playback of the sound.Methods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, setObjectName, tr
-
Constructor Details
-
WSound
public WSound()Constructs a sound object. -
WSound
Constructs a sound object for an MP3 media source.The
url
will be assumed to be an MP3 file. -
WSound
Constructs a sound object.
-
-
Method Details
-
addSource
Adds a media source.You may add multiple media sources (with different encodings) to allow the file to be played in more browsers without needing Flash plugins.
-
getSource
Returns the media source.This returns the link set for a specific encoding, or an empty link if no URL was set for that encoding.
-
setLoops
public void setLoops(int number) Sets the amount of times the sound has to be repeated.A call to
play()
will play the soundnumber
of times. The default value is 1 (no repeats). -
getLoops
public int getLoops()Returns the configured number of repeats. -
play
public void play()Start asynchronous playback of the sound.This method returns immediately. It will cause the sound to be played for the configured amount of
getLoops()
.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 callstop()
beforeplay()
if you want to avoid mixing multiple instances of a singleWSound
object. -
stop
public void stop()Stops playback of the sound.This method returns immediately. It causes the current playback (if any) of the sound to be stopped.
-