AudioPlayer
ITSLanguage AudioPlayer non-graphical component.
Constructor Summary
Public Constructor | ||
public |
constructor(options: Object) Construct an AudioPlayer for playing .wav or .mp3 files. |
Member Summary
Public Members | ||
public |
canUseAudio: * |
Private Members | ||
private |
|
|
private |
|
|
private |
_emitter: * |
|
private |
|
|
private |
_settings: * |
|
private |
_stopwatch: * |
Method Summary
Public Methods | ||
public |
addEventListener(name: string, handler: Function) Add an event listener. |
|
public |
bindStopwatch(tickCb: Function): Stopwatch Bind a stopwatch to sync with the playing and stopping functionality of the player. |
|
public |
Returns ready state of the player. |
|
public |
Gets the audio level of the current loaded audio. |
|
public |
Returns the percentage of which the buffer is filled. |
|
public |
Returns the current playing time as offset in seconds from the start. |
|
public |
Returns the total duration in seconds. |
|
public |
Get the playback rate of the current loaded audio. |
|
public |
Return the muted state of the current loaded audio. |
|
public |
Check if there is playback in progress. |
|
public |
Preload audio from an URL. |
|
public |
pause() Pause playback of audio. |
|
public |
Start or continue playback of audio. |
|
public |
preload() Start preloading audio. |
|
public |
removeEventListener(name: string, handler: Function) Remove an event listener of the player. |
|
public |
reset() Unload previously loaded audio. |
|
public |
Turn off all event listeners for this player. |
|
public |
Start playing audio at the given offset. |
|
public |
setAudioMute(shouldMute: boolean) Manually set the muted state of the current loaded audio. |
|
public |
setAudioVolume(volume: number) Sets the audio level of the current loaded audio. |
|
public |
setPlaybackRate(rate: number) Set the playback rate of the audio. |
|
public |
stop() Stop playback of audio. |
|
public |
Toggle the current playing audio to be muted or not. |
|
public |
Toggle audio playback. |
Private Methods | ||
private |
_getPlayer(callbacks: Function): * Get a player object that performs audio compression, when available. |
|
private |
Check for mandatory browser compatibility. |
Public Constructors
public constructor(options: Object) source
Construct an AudioPlayer for playing .wav or .mp3 files.
Params:
Name | Type | Attribute | Description |
options | Object |
|
Override any of the default settings. |
Emit:
Event |
'playbackstopped' When playback has ended, been stopped or been paused. |
Event |
All events the HTML5 Audio also fires. {@link http://www.w3schools.com/tags/ref_av_dom.asp} |
Public Members
public canUseAudio: * source
Private Members
private _emitter: * source
private _player: WebAudioPlayer source
private _settings: * source
private _stopwatch: * source
Public Methods
public addEventListener(name: string, handler: Function) source
Add an event listener. Listens to events emitted from the player.
public bindStopwatch(tickCb: Function): Stopwatch source
Bind a stopwatch to sync with the playing and stopping functionality of the player.
Params:
Name | Type | Attribute | Description |
tickCb | Function | Callback to invoke on every tick. A tick occurs once every 100 ms. |
Throw:
If _tickCb is null. |
public canPlay(): boolean source
Returns ready state of the player.
Return:
boolean | True when player is ready to start loading data or play. False when no audio is loaded or the player is preparing. |
public getAudioVolume(): number source
Gets the audio level of the current loaded audio. Valid values are from 0 (0%) to 1 (100%).
public getCurrentTime(): number source
Returns the current playing time as offset in seconds from the start.
public load(url: string, preload: boolean, loadedCb: Function) source
Preload audio from an URL.
Params:
Name | Type | Attribute | Description |
url | string | The URL that contains the audio. |
|
preload | boolean |
|
Try preloading metadata and possible some audio. Set to false to not download anything until playing. |
loadedCb | Function |
|
The callback that is invoked when the duration of the audio file is first known. |
Emit:
Event |
'canplay' When the player is ready to play. |
public play(position: number) source
Start or continue playback of audio. Also starts the stopwatch at the given position.
Params:
Name | Type | Attribute | Description |
position | number |
|
When position is given, start playing from this position (seconds). |
public removeEventListener(name: string, handler: Function) source
Remove an event listener of the player.
public reset() source
Unload previously loaded audio. Stops the player and any stopwatch.
Emit:
Event |
'unloaded' |
public scrub(percentage: number) source
Start playing audio at the given offset. Corrects a percentage under 0 or above 100 to the respective values.
Params:
Name | Type | Attribute | Description |
percentage | number | Start at this percentage (0..100) of the audio stream. |
public setAudioMute(shouldMute: boolean) source
Manually set the muted state of the current loaded audio.
Params:
Name | Type | Attribute | Description |
shouldMute | boolean | Whether the audio should be muted or unmuted. |
public setAudioVolume(volume: number) source
Sets the audio level of the current loaded audio. Valid values are from 0 (0%) to 1 (100%).
Params:
Name | Type | Attribute | Description |
volume | number | Volume value from 0 to 1. |
public setPlaybackRate(rate: number) source
Set the playback rate of the audio. Values are used according to HTML5 Audio. Example values: 1.0 is normal speed. 0.5 is half speed (slower). 2.0 is double speed (faster). -1.0 is backwards, normal speed. *-0.5 is backwards, half speed.
Params:
Name | Type | Attribute | Description |
rate | number | Rate at which to change the audio playback. |
public toggleAudioMute() source
Toggle the current playing audio to be muted or not. If the audio will be muted, the current audio level is remembered and can be unmuted to continue at this same audio level.
Private Methods
private _getPlayer(callbacks: Function): * source
Get a player object that performs audio compression, when available.
Using the Media Stream Recording API for recording is the preferred solution. It allows recording compressed audio which makes it quicker to submit. If not available, use a default createScriptProcessor is used.
Params:
Name | Type | Attribute | Description |
callbacks | Function | Callbacks to add to the chosen player. |
Return:
* |