Skip to content

Asset Class Reference

Devon Govett edited this page Sep 3, 2013 · 8 revisions

The AV.Asset class is responsible for managing all aspects of the decoding pipeline from source to decoder. You can use the AV.Asset class to inspect information about an audio file, such as its format, metadata, and duration, as well as actually decode the file to raw linear PCM audio data.

Constructors

Properties

Methods

Events

Constructors

new AV.Asset(source)

Creates an AV.Asset with the specified AV.Source.

Asset.fromURL(url)

Creates an AV.Asset with an AV.HTTPSource pointing to the specified url.

Asset.fromFile(file)

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

Asset.fromBuffer(buffer)

Creates an AV.Asset with an AV.BufferSource created from the specified buffer. buffer can be an AV.Buffer, an ArrayBuffer, a typed array, a Node Buffer, or even an AV.BufferList for decoding sequences of buffers.

Properties

AV.Asset#buffered

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

AV.Asset#duration

The duration of the audio file in milliseconds.

AV.Asset#format

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

AV.Asset#metadata

An object containing any metadata embedded in the audio file.

AV.Asset#active

A boolean indicating whether the decoding pipeline is currently active.

AV.Asset#source

The backing AV.Source object for the asset.

AV.Asset#demuxer

The backing AV.Demuxer object for the asset, or null if demuxing hasn't started yet.

Asset#decoder

The backing AV.Decoder object for the asset, or null if decoding hasn't started yet.

Methods

AV.Asset#start()

Starts the decoding process of the asset.

AV.Asset#stop()

Pauses the decoding process of the asset.

AV.Asset#get(event, callback)

Used for inspecting various parts of an audio file without actually decoding the entire file. event is allowed to be either 'format', 'duration', or 'metadata'. If the requested property has already been decoded at the time get is called, the callback is invoked immediately. Otherwise, the asset waits until the requested event is emitted, at which point the callback is called and decoding is stopped.

AV.Asset#decodeToBuffer(callback)

Decodes the entire file and calls callback with a single Float32Array containing the decoded samples. It is preferrable to use the streaming decoding APIs (e.g. data events), so use this as a last resort when using such a streaming API is impossible.

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.

'decodeStart'

Emitted when decoding of the actual audio data begins.

'data', buffer

Emitted when audio data is decoded. buffer is a Float32Array containing decoded Linear PCM audio. The data emitted by this event is always a Float32Array; if you need the original data as returned by the decoder, use the decoder's data event.

'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.