Class WSound
public class WSound extends WObject
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
Constructors Constructor Description WSound()
Constructs a sound object.WSound(WMediaPlayer.Encoding encoding, WLink link)
Constructs a sound object.WSound(WMediaPlayer.Encoding encoding, WLink link, WObject parent)
Constructs a sound object.WSound(WObject parent)
Constructs a sound object.WSound(java.lang.String url)
Constructs a sound object for an MP3 media source.WSound(java.lang.String url, WObject parent)
Constructs a sound object for an MP3 media source. -
Method Summary
Modifier and Type Method Description void
addSource(WMediaPlayer.Encoding encoding, WLink link)
Adds a media source.int
getLoops()
Returns the configured number of repeats.WLink
getSource(WMediaPlayer.Encoding encoding)
Returns the media source.java.lang.String
getUrl()
Deprecated.use getSource(WMediaPlayer::Encoding) instead.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
addChild, getId, getObjectName, remove, setFormData, setObjectName, tr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WSound
Constructs a sound object. -
WSound
public WSound()Constructs a sound object.Calls
this((WObject)null)
-
WSound
Constructs a sound object for an MP3 media source.The
url
will be assumed to be an MP3 file. -
WSound
public WSound(java.lang.String url)Constructs a sound object for an MP3 media source.Calls
this(url, (WObject)null)
-
WSound
Constructs a sound object. -
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.
-
getUrl
public java.lang.String getUrl()Deprecated.use getSource(WMediaPlayer::Encoding) instead.Returns the media source (deprecated). -
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.
-