Class WAudio

    • Constructor Detail

      • WAudio

        public WAudio()
        Creates a WAudio with no audio clips. Audio clips must be added later by calling one of the setAudio(...) methods.
      • WAudio

        public WAudio​(Audio audio)
        Creates a WAudio with a given audio clip.
        Parameters:
        audio - the audio clip
      • WAudio

        public WAudio​(String resource)

        Creates a WAudio with the given static content. This is provided as a convenience method for when the audio file is included as static content in the class path rather than in the web application's resources.

        The mime type for the audio clip is looked up from the "mimeType.*" mapping configuration parameters using the resource's file extension.

        Parameters:
        resource - the resource path to the audio file
      • WAudio

        public WAudio​(Audio[] audio)
        Creates a WAudio with the given audio clip in multiple formats. The client will try to load the first audio clip, and if it fails or isn't supported, it will move on to the next audio clip. Only the first clip which can be played on the client will be used.
        Parameters:
        audio - multiple formats for the same the audio clip
    • Method Detail

      • setAudio

        public void setAudio​(Audio audio)
        Sets the audio clip for all users.
        Parameters:
        audio - the audio clip
      • setAudio

        public void setAudio​(Audio[] audio)
        Sets the audio clip in multiple formats for all users. The client will try to load the first audio clip, and if it fails or isn't supported, it will move on to the next audio clip. Only the first clip which can be played on the client will be used.
        Parameters:
        audio - multiple formats for the same the audio clip
      • getAudio

        public Audio[] getAudio()
        Retrieves the audio clips associated with this WAudio.
        Returns:
        the audio clips, may be null
      • isDisabled

        @Deprecated
        public boolean isDisabled()
        Deprecated.
        never supported, not part of HTML spec, no browser support for disabled audio
        Indicates whether the audio component is disabled.
        Specified by:
        isDisabled in interface Disableable
        Returns:
        true if the component is disabled, otherwise false
      • setDisabled

        @Deprecated
        public void setDisabled​(boolean disabled)
        Deprecated.
        never supported, not part of HTML spec, no browser support for disabled audio
        Sets whether the audio component is disabled.
        Specified by:
        setDisabled in interface Disableable
        Parameters:
        disabled - if true, the component is disabled. If false, it is enabled
      • isAutoplay

        public boolean isAutoplay()
        Returns:
        true if the clip should start playing automatically, false for a manual start
      • setAutoplay

        public void setAutoplay​(boolean autoplay)

        Sets whether the clip should play automatically. It is recommended that this should not be set true.

        Each instance of WAudio which is set to auto-play must comply with guideline 1.4.2; therefore this setting is ignored if the WAudio component uses WAudio.Controls.NONE.

        Parameters:
        autoplay - true to start playing automatically, false for a manual start
      • getMediaGroup

        public String getMediaGroup()
        Returns:
        the media group name.
      • setMediaGroup

        public void setMediaGroup​(String mediaGroup)
        Sets the media group. Not currently implemented in the client due to lack of browser support.
        Parameters:
        mediaGroup - The media group name
      • isLoop

        public boolean isLoop()
        Indicates whether the audio clip playback should loop.
        Returns:
        true to loop, false to stop at the end
      • setLoop

        public void setLoop​(boolean loop)
        Sets whether the audio clip playback should loop or stop at the end. It is recommended that this not be set true as this could cause significant usability issues for some users.
        Parameters:
        loop - true to loop, false to stop at the end
      • getPreload

        public WAudio.Preload getPreload()
        Indicates how pre-loading of content should occur before the clip is played.
        Returns:
        the pre-loading mode
      • setPreload

        public void setPreload​(WAudio.Preload preload)
        Sets how pre-loading of content should occur before the clip is played.
        Parameters:
        preload - the pre-loading mode
      • getAltText

        @Deprecated
        public String getAltText()
        Deprecated.
        Not part of HTML spec
        Returns:
        alternative text to display when the audio clip can not be played.
      • setAltText

        @Deprecated
        public void setAltText​(String altText)
        Deprecated.
        Not part of HTML spec
        Sets the alternative text to display when the audio clip can not be played.
        Parameters:
        altText - the text to set
      • setMuted

        public void setMuted​(boolean muted)
        Sets the muted-on-load state of the audio player.
        Parameters:
        muted - if true the media player loads in a muted state
      • isMuted

        public boolean isMuted()
        Returns:
        the on-load muted state of the audio player
      • getAudioUrls

        public String[] getAudioUrls()
        Creates dynamic URLs that the audio clips can be loaded from. In fact the URL points to the main application servlet, but includes a non-null for the parameter associated with this WComponent (ie, its label). The handleRequest method below detects this when the browser requests a file.
        Returns:
        the urls to load the audio files from, or null if there are no clips defined
      • isVisible

        public boolean isVisible()
        Override isVisible to also return false if there are no audio clips to play.
        Specified by:
        isVisible in interface WComponent
        Overrides:
        isVisible in class AbstractWComponent
        Returns:
        true if this component is visible in the given context, otherwise false
      • handleRequest

        public void handleRequest​(Request request)
        When an audio element is rendered to the client, the browser will make a second request to get the audio content. The handleRequest method has been overridden to detect whether the request is the "content fetch" request by looking for the parameter that we encode in the content url.
        Specified by:
        handleRequest in interface WComponent
        Overrides:
        handleRequest in class AbstractWComponent
        Parameters:
        request - the request being responded to
      • getCacheKey

        public String getCacheKey()
        Returns:
        the cacheKey
      • setCacheKey

        public void setCacheKey​(String cacheKey)
        Set a cache key to make the audio cacheable on the client. All audio which it is permissible to cache should have a cache key set. Audio* which is never to be reproduced (such as an audio CAPTCHA) should not have a cache key set.
        Parameters:
        cacheKey - the cacheKey to set
      • isRenderControls

        public boolean isRenderControls()
        Returns:
        true if the browser should render the default controls.
      • setRenderControls

        public void setRenderControls​(boolean renderControls)
        Sets whether the browser should render the default controls. The default is true.
        Parameters:
        renderControls - if true then the controls are rendered
      • setControls

        @Deprecated
        public void setControls​(WAudio.Controls controls)
        Sets which playback controls to display on the audio component. The browser controls will be used unless Controls.NONE is passed in.
        Parameters:
        controls - the playback controls to display
      • getTargetId

        public String getTargetId()
        Returns the id to use to target this component.
        Specified by:
        getTargetId in interface Targetable
        Returns:
        this component's target id
      • getComponentModel

        protected WAudio.AudioModel getComponentModel()
        Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.
        Overrides:
        getComponentModel in class AbstractWComponent
        Returns:
        the effective component model
      • getOrCreateComponentModel

        protected WAudio.AudioModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class AbstractWComponent
        Returns:
        the model for this component