JavaScript

A5.audioPlayer Class

Arguments

settingsobject

Settings for the audio player. This will override the initial values of the properties of the A5.audio.Player class.

Description

Audio player class.

Properties

heartbeatnumber

Rate of heartbeat in seconds, "0" equals no heartbeat, the default in "0.25".

loopboolean

Whether to loop playback.

onBeforePlayfunction()

Event for when playback is initiated, before playing has started. If still buffering "onPlay" will happen after "onLoaded". This event fires for both inital play, and resuming from paused.

onPlayfunction()

Event fired when playback starts. This event fires for both inital play, and resuming from paused.

onPausefunction()

Event fired when playback is paused.

onChangefunction(data)

Event fired when audio player state changes.

dataobject

The data for the change event

typestring

The type of change. "timeupdate" while playing, "durationchange" when the duration of the audio is availble or changes, "buffer" while the audio file is being buffered.

onBeforeLoadfunction(src)

Event fired before audio is loaded.

srcarray

An array of the sources of the audio file to load.

onLoadedfunction()

Event fired when audio is loaded. The "onChange" events "durationchange" type should be used to update display of the duration as the duration may not be avaiblibe on some devices when "onLoaded" fires.

onErrorfunction()

Event fired when audio fails to load.

onDonefunction(data)

Event fired when playback is done, either by reaching the end, or by being stopped by the A5.audio.Player.stop() method.

dataobject

The data for the done event

typestring

The type of done event. "end" for when the player hits the end on the audio while playing, "stop" for when the A5.audio.Player.stop() method is called.

stateobject

The state of the audio player. State is updated by audio events, if you want to refresh "stale" state information use the A5.audio.Player.getState() method.

loadedboolean

Whether the audio is loaded.

srcstringboolean

The source of the audio.

streamboolean

Whether the audio is a stream.

playingboolean

Whether the audio is playing.

buffernumber

Amount buffered, a value between 0.0 and 1.0.

currentnumber

Current play time of the audio in seconds.

durationnumber

Total duration of the audio in seconds.

volumenumber

Current volume, a value between 0.0 and 1.0.

mutedboolean

Whether the audio is muted.

Methods

getState Method

Refresh and return the state of the A5.audio.Player.

load Method

Load an audio file to play.

mute Method

Set whether the audio playback is muted.

pause Method

Pause the audio.

play Method

Play the audio. This will start audio playing from the current time. If the current time is at the end of the audio, audio will start playing from the beginning.

seek Method

Seek to a given time in the audio.

stop Method

Stop audio playback and set the current time back to "0".

togglePlay Method

Toggle between playing and pausing the audio.

volume Method

Set the volume of the audio playback.

See Also