Class WAudio
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WAudio
-
- All Implemented Interfaces:
AjaxTarget
,Disableable
,SubordinateTarget
,Targetable
,WComponent
,WebComponent
,Serializable
public class WAudio extends AbstractWComponent implements Targetable, AjaxTarget, Disableable, SubordinateTarget
WAudio provides a means to play audio content.
Each WAudio component must have at least one
Audio
resource. Each such resource should be appropriate for delivery over the web and in a format suitable for the application's target browsers. If the application has a mixed browser matrix then it may be appropriate to attach multiple sources to each WAudio. It is strongly recommended that AVI files are never used as an Audio resource.Every use of WAudio must comply with the requirements outlined in Media Accessibility User Requirements, and meet guidelines 1.2, 1.4.2 and 1.4.7.
- Since:
- 1.0.0
- Author:
- Yiannis Paschalidis
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WAudio.AudioModel
Holds the extrinsic state information of a WAudio.static class
WAudio.Controls
Deprecated.Note that the only options for HTML audio element are to show native controls or not.static class
WAudio.Preload
This is used to indicate whether pre-loading of content should occur before the clip is played.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Constructor Summary
Constructors Constructor Description WAudio()
Creates a WAudio with no audio clips.WAudio(Audio audio)
Creates a WAudio with a given audio clip.WAudio(Audio[] audio)
Creates a WAudio with the given audio clip in multiple formats.WAudio(String resource)
Creates a WAudio with the given static content.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
getAltText()
Deprecated.Not part of HTML specAudio[]
getAudio()
Retrieves the audio clips associated with this WAudio.String[]
getAudioUrls()
Creates dynamic URLs that the audio clips can be loaded from.String
getCacheKey()
protected WAudio.AudioModel
getComponentModel()
Returns the effective component model for this component.WAudio.Controls
getControls()
Deprecated.String
getMediaGroup()
protected WAudio.AudioModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.WAudio.Preload
getPreload()
Indicates how pre-loading of content should occur before the clip is played.String
getTargetId()
Returns the id to use to target this component.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.boolean
isAutoplay()
boolean
isDisabled()
Deprecated.never supported, not part of HTML spec, no browser support for disabled audioboolean
isLoop()
Indicates whether the audio clip playback should loop.boolean
isMuted()
boolean
isRenderControls()
boolean
isVisible()
Override isVisible to also return false if there are no audio clips to play.protected WAudio.AudioModel
newComponentModel()
Creates a new component model appropriate for this component.void
setAltText(String altText)
Deprecated.Not part of HTML specvoid
setAudio(Audio audio)
Sets the audio clip for all users.void
setAudio(Audio[] audio)
Sets the audio clip in multiple formats for all users.void
setAutoplay(boolean autoplay)
Sets whether the clip should play automatically.void
setCacheKey(String cacheKey)
Set a cache key to make the audio cacheable on the client.void
setControls(WAudio.Controls controls)
Deprecated.void
setDisabled(boolean disabled)
Deprecated.never supported, not part of HTML spec, no browser support for disabled audiovoid
setLoop(boolean loop)
Sets whether the audio clip playback should loop or stop at the end.void
setMediaGroup(String mediaGroup)
Sets the media group.void
setMuted(boolean muted)
Sets the muted-on-load state of the audio player.void
setPreload(WAudio.Preload preload)
Sets how pre-loading of content should occur before the clip is played.void
setRenderControls(boolean renderControls)
Sets whether the browser should render the default controls.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContext, tidyUpUIContextForTree, toString, validate, validateComponent, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
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 audioIndicates whether the audio component is disabled.- Specified by:
isDisabled
in interfaceDisableable
- 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 audioSets whether the audio component is disabled.- Specified by:
setDisabled
in interfaceDisableable
- 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 settrue
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 specSets 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 interfaceWComponent
- Overrides:
isVisible
in classAbstractWComponent
- 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 interfaceWComponent
- Overrides:
handleRequest
in classAbstractWComponent
- 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
-
getControls
@Deprecated public WAudio.Controls getControls()
Deprecated.Indicates which playback controls to display on the audio component.- Returns:
- the playback controls to display
-
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)
Deprecated.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 interfaceTargetable
- Returns:
- this component's target id
-
newComponentModel
protected WAudio.AudioModel newComponentModel()
Creates a new component model appropriate for this component.- Overrides:
newComponentModel
in classAbstractWComponent
- Returns:
- a new AudioModel
-
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 classAbstractWComponent
- 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 classAbstractWComponent
- Returns:
- the model for this component
-
-