@phifans/audio
    Preparing search index...

    Class Clip

    An audio clip handles everything about audio data.

    You can create an audio clip with a file, an ArrayBuffer, or just pass a url.

    const clip = await Clip.from('https://example.com/clip.mp3');
    

    You can't play a clip directly; instead you need to either connect the clip to a Channel:

    const channel = Bus.createChannel('main');
    // Connect the clip with an audio channel, could be used to play musics.
    clip.channel = channel;
    clip.play(); // Now you can get clip progress via `clip.currentTime`.

    ...or push it to Channel#clipQueue:

    const channel = Bus.createChannel('sfx');
    // Push the clip to channel queue, could be used to play SFX, hitsound, etc.
    channel.startTick(); // Remember to start the ticker first!
    channel.pushClipToQueue(clip); // The clip will be played in next frame.
    Index

    Constructors

    • Parameters

      • audioBuffer: AudioBuffer
      • channel: null | Channel = null

      Returns Clip

    Properties

    source: AudioBuffer

    The clip source.

    Accessors

    • get channel(): null | Channel

      The channel connected to this clip.

      Returns null | Channel

    • set channel(channel: null | Channel): void

      Set the channel connected to this clip. Leave null to disconnect.

      Parameters

      Returns void

    • get currentTime(): number

      The current play progress of this clip. Only usable when connected with a Channel. Can't get clip progress when Clip#loop is true.

      Returns number

    • get duration(): number

      The audio clip duration.

      Returns number

    • get loop(): boolean

      Is this clip will be replayed when the audio reaches the end?

      Returns boolean

    • set loop(bool: boolean): void

      Set if this clip will be replayed when the audio reaches the end. Can't be set when this clip is playing.

      Parameters

      • bool: boolean

      Returns void

    • get speed(): number

      Get the playback speed of this clip.

      Returns number

    • set speed(speed: number): void

      Set the playback speed of this clip.

      Parameters

      • speed: number

      Returns void

    • get status(): -1 | 0 | 1

      Play status for this clip.

      • -1: Stop
      • 1: Playing
      • 0: Paused

      Returns -1 | 0 | 1

    Methods

    • Destroy the clip. This will stop the clip playing and disconnect to the channel.

      Returns void

    • Play the clip. The clip must be connected to any Channel to play.

      Returns void

    • Seek clip play progress. Note that you cannot seek when clip is not connected to any channels or Clip#status is stopped.

      Parameters

      • seconds: number

        Seconds that needs seek to.

      Returns void

    • Stop the clip playing.

      Returns void

    • Create a clip from supported source.

      Parameters

      • source: ClipSource

        The source of the clip, could be File, ArrayBuffer and url link.

      • Optionalchannel: null | Channel = null

        The channel linked to this clip, leave null to unset.

      Returns Promise<Clip>

      Returns the clip itself.