Skip to content

Player Class Reference

Mathijs van Velde edited this page Jul 30, 2015 · 10 revisions

The AV.Player class plays back audio data from various sources as decoded by the AV.Asset class. In addition, it handles common audio filters like panning and volume adjustment, and interfacing with an AV.AudioDevice to keep track of the playback time.

Constructors

Properties

Methods

Events

Constructors

new AV.Player(asset)

Creates a AV.Player with the specified AV.Asset.

AV.Player.fromURL(url)

Creates a AV.Player with an AV.Asset pointing to the specified url.

AV.Player.fromFile(file)

Creates an AV.Player with a AV.Asset pointing to the specified File.

AV.Player.fromBuffer(buffer)

Creates an AV.Player with an AV.BufferSource pointing to the specified buffer.

buffer can be one of the following:

  • an AV.Buffer,
  • an ArrayBuffer,
  • a typed array,
  • a Node Buffer, or
  • even an AV.BufferList for decoding sequences of buffers.

Properties

AV.Player#buffered

The percentage of the audio file that has been buffered by the source.

AV.Player#duration

The duration of the audio file in milliseconds.

AV.Player#playing

Whether the file is currently playing.

AV.Player#currentTime

The current playback time in milliseconds.

AV.Player#volume

The volume of the player as a percentage from 0 to 100. Change this property to adjust the output volume.

AV.Player#pan

The stereo pan of the player as a percentage from 0 to 100.

AV.Player#format

The format object describing the audio format as returned by the demuxer.

AV.Player#metadata

An object containing any metadata embedded in the audio file.

AV.Player#asset

The backing AV.Asset for the player.

AV.Player#filters

An array of AV.Filters that should be applied to the output audio. Initially contains a AV.VolumeFilter and a AV.PanFilter.

Methods

AV.Player#preload()

Starts loading the asset without playing it.

AV.Player#play()

Starts playback for the asset. If it hasn't been preloaded yet, preload will be called for you.

AV.Player#pause()

Pauses playback for the asset such that calling play will start playback where it left off.

AV.Player#togglePlayback()

If the player is paused, start playback. If the player is already playing, pause playback.

AV.Player#stop()

Stops playback of the asset in a destructive way.

Events

'buffer', percent

Emitted while the audio file is being loaded with a percentage between 0 and 100 representing the amount of the file that has been read so far.

'format', object

Emitted when the demuxer has decoded enough information to determine basic format information about the audio file.

'duration', msecs

Emitted when the duration of the audio file has been parsed.

'metadata', object

Emitted when any embedded metadata is decoded.

'ready'

Emitted when the audio file is ready to play.

'progress', msecs

Emitted while the audio file is playing with updates to the current playback time in milliseconds.

'error', err

Emitted when the an error is encountered in the decoding process. Whenever an error is encountered, the decoding process is also stopped automatically.

'end'

Emitted when the audio file ends.