- Utility
Contains various utility methods.
- EventTarget
Provides methods to work with events.
Meant to be extended by other classes.
- Audio
Links to the internal AudioContext and related objects.
- Track ⇐
EventTarget
Provides audiotrack-specific methods.
- Playlist ⇐
EventTarget
Provides playlist-specific methods.
- WebAudioPlayer ⇐
EventTarget
The main, public class, providing general methods.
- eventListener :
function
Callback to execute on events.
The callback context is the object on which the addEventListener() method was called.
- markerCallback :
function
Callback to execute on time markers.
Contains various utility methods.
Kind: global class
- Utility
- .audio ⇒
Audio
- .player
- .player ⇒
WebAudioPlayer
- .getArrayBuffer(url) ⇒
Promise.<ArrayBuffer, Error>
- .loadUrl(urls) ⇒
Promise.<AudioBuffer, Error>
- .getUrlPromise(urls) ⇒
Promise.<AudioBuffer, Error>
|undefined
- .removeUrlPromise(urls)
- .setUrlPromise(urls, promise)
- .readStorage(key) ⇒
*
|null
|undefined
- .updateStorage(key, value)
- .audio ⇒
Utility.audio ⇒ Audio
Returns the Audio object.
Kind: static property of Utility
Returns: Audio
- The Audio object.
Read only: true
Saves the WebAudioPlayer instance to a statically cached variable.
Kind: static property of Utility
Throws:
TypeError
If provided parameter is not a WebAudioPlayer instance.
Param | Type | Description |
---|---|---|
player | WebAudioPlayer |
The WebAudioPlayer instance. |
Utility.player ⇒ WebAudioPlayer
Returns the WebAudioPlayer instance.
Kind: static property of Utility
Returns: WebAudioPlayer
- The WebAudioPlayer instance.
Makes an XMLHttpRequest to url to get an array buffer.
Kind: static method of Utility
Returns: Promise.<ArrayBuffer, Error>
- The Promise object.
Fulfill callback arguments:
- {ArrayBuffer} The ArrayBuffer object. Reject callback arguments:
- {Error} The Error object.
Param | Type | Description |
---|---|---|
url | string |
URL to get. |
Loads the audio file by URL into buffer.
Kind: static method of Utility
Returns: Promise.<AudioBuffer, Error>
- The Promise object.
Fulfill callback arguments:
- {AudioBuffer} The AudioBuffer object containing raw audio data. Reject callback arguments:
- {Error} The Error object.
Param | Type | Description |
---|---|---|
urls | Array.<string> |
An array of mirror URLs. |
Gets a promise about loading URLs.
Kind: static method of Utility
Returns: Promise.<AudioBuffer, Error>
| undefined
- The Promise object if one exists at least for one of given URLs.
Fulfill callback arguments:
- {AudioBuffer} The AudioBuffer object containing raw audio data. Reject callback arguments:
- {Error} The Error object.
Param | Type | Description |
---|---|---|
urls | Array.<string> |
An array of mirror URLs. |
Removes promises about loading URLs.
Kind: static method of Utility
Param | Type | Description |
---|---|---|
urls | Array.<string> |
An array of mirror URLs. |
Saves the promise about loading URLs in temporary static cache.
Kind: static method of Utility
Param | Type | Description |
---|---|---|
urls | Array.<string> |
An array of mirror URLs. |
promise | Promise |
The Promise object. |
Reads data from the storage.
Kind: static method of Utility
Returns: *
| null
| undefined
- Variable value if it exists in the storage, null if it doesn't, or
undefined in case of undefined local storage.
Param | Type | Description |
---|---|---|
key | string |
Variable key. |
Updates data in the storage.
Kind: static method of Utility
Param | Type | Description |
---|---|---|
key | string |
Variable key. |
value | * |
Variable value. |
Provides methods to work with events.
Meant to be extended by other classes.
Kind: global class
Constructs an EventTarget object.
Contains event listeners.
Object keys are event types, and values are arrays of callbacks.
Kind: instance property of EventTarget
Registers an event handler of a specific type.
Kind: instance method of EventTarget
Param | Type | Description |
---|---|---|
type | string |
Event type to listen for. |
callback | eventListener |
Event handler to call when event occurs. |
Removes an event listener.
Kind: instance method of EventTarget
Param | Type | Description |
---|---|---|
type | string |
Event type. |
callback | eventListener |
Event handler to remove. |
Dispatches an event.
Kind: instance method of EventTarget
Param | Type | Description |
---|---|---|
type | string |
Event type to dispatch. |
...other_arguments | * |
Other arguments to supply to event listeners. |
Links to the internal AudioContext and related objects.
Kind: global class
- Audio
- new Audio()
- .Context :
AudioContext
- .OfflineContext :
OfflineAudioContext
- .Analyser :
AnalyserNode
- .Gain :
GainNode
- .ScriptProcessor :
ScriptProcessorNode
- .filters :
Array.<BiquadFilterNode>
Constructs an Audio object.
The AudioContext object.
Kind: instance property of Audio
The OfflineAudioContext object.
Kind: instance property of Audio
The AnalyserNode object.
Kind: instance property of Audio
The GainNode object.
Kind: instance property of Audio
The ScriptProcessorNode object.
Kind: instance property of Audio
Array of BiquadFilterNode objects.
Kind: instance property of Audio
Track ⇐ EventTarget
Provides audiotrack-specific methods.
Kind: global class
Extends: EventTarget
- Track ⇐
EventTarget
- new Track(urls)
- .data :
object
- .eventListeners :
object
- .load() ⇒
Promise.<Track, Error>
- .play() ⇒
Track
- .stop() ⇒
Track
- .pause() ⇒
Track
- .seek(newOffset) ⇒
Track
- .when(marker, callback) ⇒
Track
- .getCurrentTime() ⇒
number
- .getPlayedTime() ⇒
number
- .getDuration() ⇒
number
- .isPlaying() ⇒
boolean
- .addEventListener(type, callback)
- .removeEventListener(type, callback)
- .dispatchEvent(type, ...other_arguments)
- "playing"
- "finished"
- "play"
Constructs a Track object.
Param | Type | Description |
---|---|---|
urls | Array.<string> |
Track sources - an array of mirror URLs pointing to the same audio piece. |
Provides a common place for any custom data associated with the track.
For example, track title, artist, etc.
Kind: instance property of Track
Contains event listeners.
Object keys are event types, and values are arrays of callbacks.
Kind: instance property of Track
Loads the audio file into buffer.
Multiple calls to this method get the same Promise object.
Kind: instance method of Track
Returns: Promise.<Track, Error>
- The Promise object.
Fulfill callback arguments:
track.play() ⇒ Track
Plays the loaded audio file or resumes the playback from pause.
Kind: instance method of Track
Returns: Track
- The Track object.
Throws:
Error
If track is not loaded.
Emits: play
track.stop() ⇒ Track
Stops the playback and resets the track state.
This method resets the current time position and the skipped time counter, which impacts the played time in the way that next play() will count it from 0.
Kind: instance method of Track
Returns: Track
- The Track object.
track.pause() ⇒ Track
Pauses the playback.
Kind: instance method of Track
Returns: Track
- The Track object.
track.seek(newOffset) ⇒ Track
Seeks on an audio track.
Kind: instance method of Track
Returns: Track
- The Track object.
Throws:
TypeError
If provided offset is negative.
Param | Type | Description |
---|---|---|
newOffset | number |
Seconds from the start of an audio file. |
track.when(marker, callback) ⇒ Track
Sets the callback to execute on a time marker.
This method uses the actual played time. It means that markers cannot be accidentally skipped if a listener skips track parts.
Kind: instance method of Track
Returns: Track
- The Track object.
Throws:
TypeError
If marker is negative.
See: getPlayedTime
Param | Type | Description |
---|---|---|
marker | number |
A time marker in seconds of actual playback. |
callback | markerCallback |
A callback to execute when marker is reached. |
Gets the current playback position.
Kind: instance method of Track
Returns: number
- Seconds from the start of an audio file.
Gets the time the track was actually played.
Kind: instance method of Track
Returns: number
- Seconds from the first play() of a track, excluding pauses and skips.
Gets the duration of a track.
Kind: instance method of Track
Returns: number
- The duration in seconds.
Throws:
Error
If track is not loaded.
Indicates whether a track is currently playing.
Kind: instance method of Track
Returns: boolean
- True if audio is playing, false otherwise.
Registers an event handler of a specific type.
Kind: instance method of Track
Param | Type | Description |
---|---|---|
type | string |
Event type to listen for. |
callback | eventListener |
Event handler to call when event occurs. |
Removes an event listener.
Kind: instance method of Track
Param | Type | Description |
---|---|---|
type | string |
Event type. |
callback | eventListener |
Event handler to remove. |
Dispatches an event.
Kind: instance method of Track
Param | Type | Description |
---|---|---|
type | string |
Event type to dispatch. |
...other_arguments | * |
Other arguments to supply to event listeners. |
Indicates that the track is playing.
Unlike the 'play' event, this one is fired constantly during the playback of the Track.
Kind: event emitted by Track
See: play
Indicates that the track has finished playing.
Kind: event emitted by Track
Indicates the playback beginning.
Unlike the 'playing' event, this one is fired only when the track source has started playing, but not necessary from the start of an audio track.
Kind: event emitted by Track
See: playing
Playlist ⇐ EventTarget
Provides playlist-specific methods.
Kind: global class
Extends: EventTarget
- Playlist ⇐
EventTarget
- new Playlist(list)
- .list :
Array.<Track>
- .repeat :
boolean
- .length ⇒
number
- .eventListeners :
object
- .setCurrentByIndex(index) ⇒
Playlist
- .getCurrent() ⇒
Track
|null
- .getCurrentIndex() ⇒
number
- .get(index) ⇒
Track
|null
|undefined
- .load(index) ⇒
Promise.<Track, Error>
- .play(index) ⇒
Playlist
- .pause() ⇒
Playlist
- .previous() ⇒
Playlist
- .next() ⇒
Playlist
- .isPlaying() ⇒
boolean
- .shuffle() ⇒
Playlist
- .push(...tracks) ⇒
Playlist
- .addEventListener(type, callback)
- .removeEventListener(type, callback)
- .dispatchEvent(type, ...other_arguments)
- "trackReady" (track)
Constructs a Playlist object.
Param | Type | Description |
---|---|---|
list | Array.<Track> |
(optional) Array of Track instances. |
playlist.list : Array.<Track>
List of tracks to play.
Kind: instance property of Playlist
Indicates whether the list is on repeat.
Kind: instance property of Playlist
Returns the number of tracks in the list.
Kind: instance property of Playlist
Returns: number
- Number of tracks in the list.
Read only: true
Contains event listeners.
Object keys are event types, and values are arrays of callbacks.
Kind: instance property of Playlist
playlist.setCurrentByIndex(index) ⇒ Playlist
Sets current track by its list index.
Kind: instance method of Playlist
Returns: Playlist
- This Playlist instance.
Throws:
Error
If current track is playing or if there's no track with given index in the list.
Param | Type | Description |
---|---|---|
index | number |
Index of a track in list. |
playlist.getCurrent() ⇒ Track
| null
Returns the current track.
Kind: instance method of Playlist
Returns: Track
| null
- The current track, or null in case of empty list.
Returns the list index of current track.
Kind: instance method of Playlist
Returns: number
- Current track's index, or -1 in case of empty list or if the current
track was removed from the list.
playlist.get(index) ⇒ Track
| null
| undefined
Returns the track by index or the current one.
Kind: instance method of Playlist
Returns: Track
| null
| undefined
- Either track corresponding to given index, or the current one. Null or
undefined, if there's no corresponding track in the list.
Param | Type | Default | Description |
---|---|---|---|
index | number | null |
|
(optional) The list index. If omitted, the current track will be looked for. If specified, and playlist is on repeat, then it will be adjusted to the range. |
Loads the track by index or the current one.
If track can't be loaded this method will try next tracks from the list recursively.
Kind: instance method of Playlist
Returns: Promise.<Track, Error>
- The Promise object.
Fulfill callback arguments:
- {Track} The Track instance, loaded. Reject callback arguments:
- {Error} The Error object.
Emits:trackReady
Param | Type | Default | Description |
---|---|---|---|
index | number | null |
|
(optional) The list index. If omitted, the current track will be loaded. |
playlist.play(index) ⇒ Playlist
Plays the loaded track by index or the current one.
If track is on pause this method will resume the playback from track's current position. If track is finished it will play from the start.
Kind: instance method of Playlist
Returns: Playlist
- This Playlist instance.
Throws:
Error
If there's no corresponding track in the list.
Param | Type | Default | Description |
---|---|---|---|
index | number | null |
|
(optional) The list index. If omitted, the current track will be played. |
playlist.pause() ⇒ Playlist
Pauses the playback of current track.
Kind: instance method of Playlist
Returns: Playlist
- This Playlist instance.
playlist.previous() ⇒ Playlist
Skips to the start of previous track in the list, if one exists.
Kind: instance method of Playlist
Returns: Playlist
- This Playlist instance.
Throws:
Error
If list is empty or if the current track was removed from the list.
playlist.next() ⇒ Playlist
Skips to the start of next track in the list, if one exists.
Kind: instance method of Playlist
Returns: Playlist
- This Playlist instance.
Throws:
Error
If list is empty or if the current track was removed from the list.
Indicates whether a current track is currently playing.
Kind: instance method of Playlist
Returns: boolean
- True if audio is playing, false otherwise.
playlist.shuffle() ⇒ Playlist
Shuffles the list.
Kind: instance method of Playlist
Returns: Playlist
- This Playlist instance.
playlist.push(...tracks) ⇒ Playlist
Adds one or more tracks to the end of the list.
Kind: instance method of Playlist
Returns: Playlist
- This Playlist instance.
Param | Type | Description |
---|---|---|
...tracks | Track |
Track instances to add. |
Registers an event handler of a specific type.
Kind: instance method of Playlist
Param | Type | Description |
---|---|---|
type | string |
Event type to listen for. |
callback | eventListener |
Event handler to call when event occurs. |
Removes an event listener.
Kind: instance method of Playlist
Param | Type | Description |
---|---|---|
type | string |
Event type. |
callback | eventListener |
Event handler to remove. |
Dispatches an event.
Kind: instance method of Playlist
Param | Type | Description |
---|---|---|
type | string |
Event type to dispatch. |
...other_arguments | * |
Other arguments to supply to event listeners. |
Indicates that the track from the list is loaded.
Kind: event emitted by Playlist
Param | Type | Description |
---|---|---|
track | Track |
Instance of the loaded track. |
WebAudioPlayer ⇐ EventTarget
The main, public class, providing general methods.
Kind: global class
Extends: EventTarget
- WebAudioPlayer ⇐
EventTarget
- new WebAudioPlayer()
- .eventListeners :
object
- .getAudio() ⇒
Audio
- .createTrack(urls) ⇒
Track
- .createPlaylist(list) ⇒
Playlist
- .setVolume(gain) ⇒
WebAudioPlayer
- .getVolume() ⇒
number
- .setEq(bands) ⇒
WebAudioPlayer
- .getEq() ⇒
Array.<number>
- .addEventListener(type, callback)
- .removeEventListener(type, callback)
- .dispatchEvent(type, ...other_arguments)
- "audioprocess"
Constructs a WebAudioPlayer object.
Contains event listeners.
Object keys are event types, and values are arrays of callbacks.
Kind: instance property of WebAudioPlayer
webAudioPlayer.getAudio() ⇒ Audio
Returns the Audio object.
Kind: instance method of WebAudioPlayer
Returns: Audio
- The Audio object.
webAudioPlayer.createTrack(urls) ⇒ Track
Returns the new Track instance.
Kind: instance method of WebAudioPlayer
Returns: Track
- The Track instance.
Param | Type | Description |
---|---|---|
urls | Array.<string> |
Track sources - an array of mirror URLs pointing to the same audio piece. Only the first valid URL will be ultimately used. |
webAudioPlayer.createPlaylist(list) ⇒ Playlist
Returns the new Playlist instance.
Kind: instance method of WebAudioPlayer
Returns: Playlist
- The Playlist instance.
Param | Type | Description |
---|---|---|
list | Array.<Track> |
(optional) Array of Track instances. |
webAudioPlayer.setVolume(gain) ⇒ WebAudioPlayer
Sets the playback volume to new level.
Kind: instance method of WebAudioPlayer
Returns: WebAudioPlayer
- The WebAudioPlayer object.
Param | Type | Description |
---|---|---|
gain | number |
Number between 0 and 1. |
Gets the current value of the playback volume level.
Kind: instance method of WebAudioPlayer
Returns: number
- Previously set value.
webAudioPlayer.setEq(bands) ⇒ WebAudioPlayer
Sets the equalizer bands to new levels.
Kind: instance method of WebAudioPlayer
Returns: WebAudioPlayer
- The WebAudioPlayer object.
Param | Type | Description |
---|---|---|
bands | Array.<number> | object |
Array or object which keys are indexes from 0 to 9 for each of 10 bands, and values are numbers indicating the new gain of the corresponding band. All elements of the object are optional, so setting less than 10 elements will leave unspecified bands in previous state. |
Gets the current band levels of the equalizer.
Kind: instance method of WebAudioPlayer
Returns: Array.<number>
- Array of 10 numbers.
Registers an event handler of a specific type.
Kind: instance method of WebAudioPlayer
Param | Type | Description |
---|---|---|
type | string |
Event type to listen for. |
callback | eventListener |
Event handler to call when event occurs. |
Removes an event listener.
Kind: instance method of WebAudioPlayer
Param | Type | Description |
---|---|---|
type | string |
Event type. |
callback | eventListener |
Event handler to remove. |
Dispatches an event.
Kind: instance method of WebAudioPlayer
Param | Type | Description |
---|---|---|
type | string |
Event type to dispatch. |
...other_arguments | * |
Other arguments to supply to event listeners. |
Indicates that audio is processing.
This event is fired constantly during the life of an Audio object and should not be generally listened for. Track objects use this event to fire their own 'playing' event to indicate when the corresponding track is actually playing.
Kind: event emitted by WebAudioPlayer
See: playing
Callback to execute on events.
The callback context is the object on which the addEventListener() method was called.
Kind: global typedef
this: EventTarget
See: dispatchEvent
Param | Type | Description |
---|---|---|
...arguments | * |
Any number of arguments supplied to the dispatchEvent() method (except its first argument - event type). |
Callback to execute on time markers.