Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AudioTrack

Creates a new audio instance compatible with the AudioChannel class. Anyways, you will able to control the final audio-source (playing, pause, loop, etc.)

Hierarchy

  • AudioTrack

Index

Constructors

  • new AudioTrack(audioSource: String | HTMLAudioElement, audioContext: AudioContext): AudioTrack
  • Create a new audio-track from a audio-element or create a new one from an URL (Base64 supported).

    WARNING: Local files with file:/// protocol are not supported (cross-origin error). To load local files please load them with FileReader and convert them into Base64.

    example

    Connecting an Element

    const el = document.querySelector( "audio" ) ;
    channel.input( el, mixer.ctx ) ;
    // or
    const track = new AudioTrack( el ) ;
    channel.input( track, myCustomAudioContext ) ;
    example

    Loading from URL

    const track1 = channel.input( "./my-file.mp3", mixer.ctx ) ;
    // Base64 is supported.
    const track2 = channel.input( "data:audio/mpeg;base64,...", mixer.ctx ) ;

    Parameters

    • audioSource: String | HTMLAudioElement
    • audioContext: AudioContext

    Returns AudioTrack

Properties

audioElement: HTMLAudioElement
sourceNode: MediaElementAudioSourceNode

Accessors

  • get loop(): boolean
  • set loop(status: boolean): void
  • Get loop status of the current track

    Returns boolean

  • Enable/Disable the loop feature of the current track

    Parameters

    • status: boolean

    Returns void

  • get muted(): boolean
  • set muted(status: boolean): void
  • Get mute status of the current track

    Returns boolean

  • Enable/Disable the mute feature of the current track

    Parameters

    • status: boolean

    Returns void

  • get paused(): boolean
  • Check if the current track is paused.

    Returns boolean

  • get playing(): boolean
  • Check if the current track is playing.

    Returns boolean

  • get time(): number
  • set time(seconds: number): void
  • Get the current time (in seconds) of the track.

    Returns number

  • Set the current time (in seconds) in of the current track. Use this property to forward or backward the audio.

    Parameters

    • seconds: number

    Returns void

  • get volume(): number
  • set volume(value: number): void
  • Get the volume of the current track (from 0 to 1)

    Returns number

  • Set the volume of the current track (from 0 to 1)

    Parameters

    • value: number

    Returns void

Methods

  • Connect the track output to a channel input.

    Parameters

    Returns undefined | true

  • pause(): void
  • Pause the current audio and resume it with play() method.

    Returns void

  • play(): Promise<void>
  • Play the current audio from the last time value. Use stop() to start from the beginning or pause() to resume the audio.

    Returns Promise<void>

  • stop(): number
  • Pause the current audio track and set time to 0, playing audio from the start again with play() method.

    Returns number

Generated using TypeDoc