Skip to content

AudioDevice Class Reference

devongovett edited this page Nov 12, 2012 · 2 revisions

The AV.AudioDevice class is responsible for interfacing with various audio APIs in browsers, keeping track of the current playback time based on the device hardware time, and the play/pause/seek state. It emits the refill event with a buffer to fill with audio data when it needs new audio data.

Constructor

Properties

Methods

Events

Constructor

new AV.AudioDevice(sampleRate, channels)

Creates a new AV.AudioDevice with the specified sample rate and number of channels.

Properties

AV.AudioDevice#playing

Whether or not the device is currently playing. Changing this property will not have any effect. Think of it as read-only. :)

AV.AudioDevice#currentTime

The current playback time in milliseconds.

Methods

AV.AudioDevice#start()

Creates the correct audio device for the current browser if it hasn't already been created, and starts emitting refill and timeUpdate events and updating the currentTime.

AV.AudioDevice#stop()

Stops emitting all events and updating currentTime.

AV.AudioDevice#seek(time)

Seeks the currentTime to the given time.

Events

'refill', buffer

Emitted whenever the device needs new audio data to play back. Emitted with a Typed Array to fill with Linear PCM audio data.

'timeUpdate', msecs

Emitted every 200 milliseconds while the device is playing with an update to the current playback time, based on the actual device time.


Device Interface

The Device interface describes the methods and properties you must implement if you want to provide support for additional audio APIs.

Constructor

Properties

Methods

Registering and Creating

Constructor

new Device(sampleRate, channels)

Creates a new instance of the device with the specified sample rate and number of channels. The device must start emitting refill events as soon as it is created.

Properties

Device.supported

Whether or not the device is supported on the current browser or platform.

Methods

Device#destroy()

Destroys the device and stops emitting refill events.

Device#getDeviceTime()

Returns the current device time.


Registering and Creating Devices

AV.AudioDevice.register(device)

Once you've implemented the Device interface, you must register it with the AudioDevice class using this method.

AV.AudioDevice.create(sampleRate, channels)

Finds the first supported audio device and returns an instance with the specified sample rate and number of channels.