Class 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 Details

  • Method Details

    • addSource

      public void addSource(MediaEncoding encoding, WLink link)
      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

      public WLink getSource(MediaEncoding encoding)
      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 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.