Skip to content

Source Interface Reference

devongovett edited this page Nov 12, 2012 · 2 revisions

The AV.Source interface describes the necessary methods one must provide to implement a valid data source for Aurora. There is no concrete AV.Source class provided by the framework, but two implementations of the interface are provided: AV.HTTPSource and AV.FileSource.

You normally do not use sources directly, but rather you use the fromURL and fromFile class methods on the AV.Asset. However, you can implement additional sources and use them with the AV.Asset constructor manually.

Required Methods

Events

Required Methods

AV.Source#start()

Causes the source to start loading data. The source must emit data, progress, and end events following the call to start. Emitting an error event will cause the pause method to be called and the loading to be aborted.

AV.Source#pause()

Causes the source to pause loading data, but not reset state such that calling start starts the source right where it left off.

AV.Source#reset()

Resets the source's state to the beginning of the data stream. If the source does not have a specific beginning (in the case of a streaming audio source for example), this method should have no effect.

Events

'data', buffer

The data event should be emitted as soon as the source has data available. Data should be emitted in chunks, and should not be loaded all at once and emitted all together if possible. The argument to the 'data' event should be an AV.Buffer object containing the loaded data.

'progress', percent

The progress event should be emitted as the data is being loaded, as often as reasonably possible. The argument should be a percentage between 0 and 100 representing the amount of data loaded (loaded / total * 100). If the total size of the file is unknown, then the event should not be emitted.

'error', err

The error event should be emitted when there is an error while loading data. It will trigger the pause and cancel loading the asset.

'end'

The end event should be triggered when the source has loaded all data available.