Audio Class
Item Index
Methods
Methods
create
(
Node
-
config
This is a utility method to create an HTML 5 Audio element. Each browser has a different level of support for playing different audio formats. If an audio file is hosted in multple formats, this will select the one most likely to play in the current browser. If the browser does not support any of the available audio formats, null is returned.
Parameters:
-
config
ObjectThe config object has the following optional properties:
- autoplay
- Boolean. If the audio should begin playing immediately.
- baseUrl
- String. URL of the audio file, minus the extension. Works together with the format property to pick the best audio file to play.
- controls
- Boolean. If the browser should render a user interface. (The audio node must be attached to the DOM for the controls to appear)
- format
- Array or Object. List of hosted formats. Defaults to ['ogg', 'mp3', 'm4a', 'wav']. The best supported format will be determined and the file extension will be appended to baseUrl. If all four formats are not being hosted, only list the formats that are. For example, ['mp3', 'ogg'] will not try to find an m4a or wav file. If the four formats aren't named the same, or are hosted at different locations, or have unusual file extensions, set the baseUrl property to any common URL fragment, or leave the baseUrl property undefined if there isn't one. Then set the format property to an object which has the individual formats as keys and a strings as values that will be appended to the baseUrl. For example, baseUrl could be set to 'http://domain.com/' and format could be set to {m4a: 'music/file.m4a', mp3: 'mp3s/cool/file.mp4', ogg: 'vorbis/file.ogg'}
- loop
- Boolean. If the audio should loop forever.
- preload
- String. This value should be either 'auto', 'metadata', or 'none'. Defaults to 'auto'.
Returns:
Node: