Options
All
  • Public
  • Public/Protected
  • All
Menu

Create a audio object. This uses the Web Audio API.

Hierarchy

  • Audio

Index

Constructors

constructor

Properties

autoplay

autoplay: boolean

Whether to start playback automatically. Default is false.

context

context: AudioContext

The AudioContext of the listener given in the constructor.

detune

detune: number

Modify pitch, measured in cents. +/- 100 is a semitone. +/- 1200 is an octave. Default is 0.

duration

duration: undefined | number

Overrides the duration of the audio. Same as the duration parameter of AudioBufferSourceNode.start(). Default is undefined to play the whole buffer.

filters

filters: BiquadFilterNode[]

Represents an array of BiquadFilterNodes. Can be used to apply a variety of low-order filters to create more complex sound effects. Filters are set via Audio.setFilter or Audio.setFilters.

gain

gain: GainNode

A GainNode created using AudioContext.createGain().

hasPlaybackControl

hasPlaybackControl: boolean

Whether playback can be controlled using the play(), pause() etc. methods. Default is true.

isPlaying

isPlaying: boolean

Whether the audio is currently playing.

listener

listener: AudioListener

A reference to the listener object of this audio.

offset

offset: number

An offset to the time within the audio buffer that playback should begin. Same as the offset parameter of AudioBufferSourceNode.start(). Default is 0.

playbackRate

playbackRate: number

Speed of playback. Default is 1.

source

source: null | AudioBufferSourceNode

An AudioBufferSourceNode created using AudioContext.createBufferSource().

sourceType

sourceType: string

Type of the audio source. Default is string 'empty'.

type

type: string

String denoting the type, set to 'Audio'.

Methods

connect

  • Connect to the Audio.source. This is used internally on initialisation and when setting / removing filters.

    Returns Audio

disconnect

  • Disconnect from the Audio.source. This is used internally when setting / removing filters.

    Returns Audio

getFilter

  • getFilter(): BiquadFilterNode

getFilters

  • getFilters(): BiquadFilterNode[]

getLoop

  • getLoop(): boolean
  • Return the value of source.loop (whether playback should loop).

    Returns boolean

getOutput

  • getOutput(): GainNode

getPlaybackRate

  • getPlaybackRate(): number

getVolume

  • getVolume(): number

onEnded

  • onEnded(): void

pause

  • pause(): undefined | Audio

play

  • play(delay?: number): undefined | Audio
  • If hasPlaybackControl is true, starts playback.

    Parameters

    • delay: number = 0

    Returns undefined | Audio

setBuffer

  • setBuffer(audioBuffer: AudioBuffer): Audio
  • Setup the source to the audioBuffer, and sets sourceType to 'buffer'. If autoplay, also starts playback.

    Parameters

    • audioBuffer: AudioBuffer

    Returns Audio

setFilter

  • setFilter(filter: BiquadFilterNode): Audio

setFilters

  • setFilters(value: BiquadFilterNode[]): Audio
  • value - arrays of filters. Applies an array of BiquadFilterNodes to the audio.

    Parameters

    • value: BiquadFilterNode[]

    Returns Audio

setLoop

  • setLoop(value: boolean): undefined | Audio
  • Set source.loop to value (whether playback should loop).

    Parameters

    • value: boolean

    Returns undefined | Audio

setLoopEnd

  • setLoopEnd(value: number): Audio

setLoopStart

  • setLoopStart(value: number): Audio

setMediaElementSource

  • setMediaElementSource(mediaElement: HTMLMediaElement): Audio
  • Applies the given object of type HTMLMediaElement as the source of this audio. Also sets hasPlaybackControl to false.

    Parameters

    • mediaElement: HTMLMediaElement

    Returns Audio

setMediaStreamSource

  • setMediaStreamSource(mediaStream: MediaStream): Audio
  • Applies the given object of type MediaStream as the source of this audio. Also sets hasPlaybackControl to false.

    Parameters

    • mediaStream: MediaStream

    Returns Audio

setNodeSource

  • setNodeSource(audioNode: AudioBufferSourceNode): Audio
  • Setup the source to the audioBuffer, and sets sourceType to 'audioNode'. Also sets hasPlaybackControl to false.

    Parameters

    • audioNode: AudioBufferSourceNode

    Returns Audio

setPlaybackRate

  • setPlaybackRate(value: number): undefined | Audio
  • If hasPlaybackControl is enabled, set the playbackRate to value.

    Parameters

    • value: number

    Returns undefined | Audio

setVolume

  • setVolume(value: number): Audio

stop

  • stop(): undefined | Audio

Generated using TypeDoc