eu.webtoolkit.jwt
Class WSound

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WSound

public class WSound
extends WObject

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).


Constructor Summary
WSound(java.lang.String url)
          Constructs a sound object that will play the given URL.
WSound(java.lang.String url, WObject parent)
          Constructs a sound object that will play the given URL.
 
Method Summary
 int getLoops()
          Returns the configured number of repeats.
 java.lang.String getUrl()
          Returns the sound url.
 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, setObjectName, tr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WSound

public WSound(java.lang.String url,
              WObject parent)
Constructs a sound object that will play the given URL.

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


WSound

public WSound(java.lang.String url)
Constructs a sound object that will play the given URL.

Calls this(url, (WObject)null)

Method Detail

getUrl

public java.lang.String getUrl()
Returns the sound url.

See Also:
WSound(String url, WObject parent)

setLoops

public void 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).


getLoops

public int getLoops()
Returns the configured number of repeats.

setLoops()


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 call stop() before play() if you want to avoid mixing multiple instances of a single WSound 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.