Class Sound

All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsWidget, LogicalStructure, HasTimeChangedHandlers

public class Sound extends BaseWidget implements HasTimeChangedHandlers
Smart GWT class for loading and playing audio files using the HTML5 <AUDIO> element.
  • Constructor Details

  • Method Details

    • getOrCreateRef

      public static Sound getOrCreateRef(JavaScriptObject jsObj)
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, Canvas defaults)
      Changes the defaults for Canvas AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - Canvas defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, FormItem defaults)
      Changes the defaults for FormItem AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - FormItem defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • create

      protected JavaScriptObject create()
      Overrides:
      create in class BaseWidget
    • setAutoLoad

      public Sound setAutoLoad(boolean autoLoad)
      Should the specified audio file be loaded automatically.

      If set to false developers may load the audio explicitly via load()

      Parameters:
      autoLoad - New autoLoad value. Default value is false
      Returns:
      Sound instance, for chaining setter calls
    • getAutoLoad

      public boolean getAutoLoad()
      Should the specified audio file be loaded automatically.

      If set to false developers may load the audio explicitly via load()

      Returns:
      Current autoLoad value. Default value is false
    • setAutoPlay

      public Sound setAutoPlay(boolean autoPlay)
      Should the specified audio file be played automatically?

      If set to false developers may play the audio explicitly via play().

      Parameters:
      autoPlay - New autoPlay value. Default value is false
      Returns:
      Sound instance, for chaining setter calls
    • getAutoPlay

      public boolean getAutoPlay()
      Should the specified audio file be played automatically?

      If set to false developers may play the audio explicitly via play().

      Returns:
      Current autoPlay value. Default value is false
    • setSrc

      public Sound setSrc(String src)
      URL of the audio file to be played by this sound instance. If multiple file URLs are supplied, the browser will make use of the first file type for which it has support.

      If this method is called after the component has been drawn/initialized: Update the src of this sound instance at runtime. Note that autoLoad and autoPlay govern whether this media will be loaded or played immediately when the src value is changed.
      Parameters:
      src - URL of new audio file to be played by this sound instance. Default value is null
      Returns:
      Sound instance, for chaining setter calls
    • getSrc

      public String getSrc()
      URL of the audio file to be played by this sound instance. If multiple file URLs are supplied, the browser will make use of the first file type for which it has support.
      Returns:
      Current src value. Default value is null
    • setSrc

      public Sound setSrc(String... src)
      URL of the audio file to be played by this sound instance. If multiple file URLs are supplied, the browser will make use of the first file type for which it has support.

      If this method is called after the component has been drawn/initialized: Update the src of this sound instance at runtime. Note that autoLoad and autoPlay govern whether this media will be loaded or played immediately when the src value is changed.
      Parameters:
      src - URL of new audio file to be played by this sound instance. Default value is null
      Returns:
      Sound instance, for chaining setter calls
    • getSrcAsStringArray

      public String[] getSrcAsStringArray()
      URL of the audio file to be played by this sound instance. If multiple file URLs are supplied, the browser will make use of the first file type for which it has support.
      Returns:
      Current src value. Default value is null
    • getCurrentTime

      public Double getCurrentTime()
      Retrieves the current playback time of a playing or paused audio file in seconds.
      Returns:
      current playback time audio file in seconds. If the file has not been loaded, or no src is defined, this method will return zero.
    • getDuration

      public Double getDuration()
      Retrieves the duration of the current audio file in seconds.
      Returns:
      duration of the audio file in seconds. If the file has not been loaded, or no src is defined, this method will return null.
    • load

      public void load()
      This method will cause the specified audio file to be loaded
    • load

      public void load(CanPlayCallback canPlayCallback)
      This method will cause the specified audio file to be loaded
      Parameters:
      canPlayCallback - notification to fire when the file is ready to play
    • pause

      public void pause()
      Pause playback of the audio file.
    • reset

      public void reset()
      If playback is currently paused, reset the playback position to the start of the audio file so a call to play() will play from the start, rather than resuming playback from the current position.
    • setCurrentTime

      public void setCurrentTime(Double time)
      Move playback to a particular time in a loaded audio file.
      Parameters:
      time - time to move to. This method will have no effect if the file has not been loaded or no src element is defined.
    • addTimeChangedHandler

      public HandlerRegistration addTimeChangedHandler(TimeChangedHandler handler)
      Add a timeChanged handler.

      Notification method fired repeatedly to indicate a change in currentTime value while an audio file is playing.

      Specified by:
      addTimeChangedHandler in interface HasTimeChangedHandlers
      Parameters:
      handler - the timeChanged handler
      Returns:
      HandlerRegistration used to remove this handler
    • isSupported

      public static boolean isSupported()
      Returns true for browsers which natively support HTML5 Audio, used by the Sound class
      Returns:
      true if Audio is supported in this browser
    • setDefaultProperties

      public static void setDefaultProperties(Sound soundProperties)
      Class level method to set the default properties of this class. If set, then all existing and subsequently created instances of this class will automatically have default properties corresponding to the properties set on the SmartGWT class instance passed to this function before its underlying SmartClient JS object was created. This is a powerful feature that eliminates the need for users to create a separate hierarchy of subclasses that only alter the default properties of this class. Can also be used for skinning / styling purposes.

      Note: This method is intended for setting default attributes only and will affect all instances of the underlying class (including those automatically generated in JavaScript). This method should not be used to apply standard EventHandlers or override methods for a class - use a custom subclass instead. Calling this method after instances have been created can result in undefined behavior, since it bypasses any setters and a class instance may have already examined a particular property and not be expecting any changes through this route.

      Parameters:
      soundProperties - properties that should be used as new defaults when instances of this class are created
      See Also:
    • play

      public void play()
      Play the audio file. If necessary the file will be loaded first.
    • play

      public void play(PlaybackCompleteCallback callback)
      Play the audio file. If necessary the file will be loaded first.
      Parameters:
      playbackCompleteCallback - notification fired when playback completes.
    • play

      public static void play(String src)
      Convenience method to load and play a specified audio file.

      For more explicit control over loading and playback of audio files, developers may create an instance of Sound and call methods directly on that object.

      Parameters:
      src - URL of the audio clip to play.
    • play

      public static void play(String src, PlaybackCompleteCallback callback)
      Convenience method to load and play a specified audio file.

      For more explicit control over loading and playback of audio files, developers may create an instance of Sound and call methods directly on that object.

      Parameters:
      src - URL of the audio clip to play.
      callback - callback to execute when the clip playback completes.
    • getSrcAsString

      public String[] getSrcAsString()
      Deprecated.
    • setLogicalStructure

      public LogicalStructureObject setLogicalStructure(SoundLogicalStructure s)
      Setter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
    • getLogicalStructure

      public LogicalStructureObject getLogicalStructure()
      Getter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
      Specified by:
      getLogicalStructure in interface LogicalStructure
      Overrides:
      getLogicalStructure in class BaseWidget