Skip to content

EZ Web Audio / playTogether

Function: playTogether() ​

Call Signature ​

playTogether(playables): Promise<void>

Defined in: packages/core/src/utils/play-together.ts:39

Play multiple sounds synchronized to the exact same AudioContext timestamp.

Uses playAt() with a shared start time slightly in the future to ensure all sources begin at precisely the same moment. This is more accurate than calling play() on each sound sequentially, which would introduce tiny timing differences.

Parameters ​

playables ​

Playable[]

Array of Playable instances (Sound, Track, Oscillator, etc.); an explicit BaseAudioContext may be passed as the first argument instead

Returns ​

Promise<void>

Promise that resolves when all sounds have started

Example ​

typescript
import { createSound, playTogether } from 'ez-web-audio'

const kick = await createSound('kick.mp3')
const snare = await createSound('snare.mp3')
const hihat = await createSound('hihat.mp3')

await playTogether([kick, snare, hihat])
// All three start at the exact same AudioContext time

// With explicit AudioContext
await playTogether(myAudioContext, [kick, snare, hihat])

Call Signature ​

playTogether(audioContext, playables): Promise<void>

Defined in: packages/core/src/utils/play-together.ts:40

Play multiple sounds synchronized to the exact same AudioContext timestamp.

Uses playAt() with a shared start time slightly in the future to ensure all sources begin at precisely the same moment. This is more accurate than calling play() on each sound sequentially, which would introduce tiny timing differences.

Parameters ​

audioContext ​

BaseAudioContext

playables ​

Playable[]

Array of Playable instances (Sound, Track, Oscillator, etc.); an explicit BaseAudioContext may be passed as the first argument instead

Returns ​

Promise<void>

Promise that resolves when all sounds have started

Example ​

typescript
import { createSound, playTogether } from 'ez-web-audio'

const kick = await createSound('kick.mp3')
const snare = await createSound('snare.mp3')
const hihat = await createSound('hihat.mp3')

await playTogether([kick, snare, hihat])
// All three start at the exact same AudioContext time

// With explicit AudioContext
await playTogether(myAudioContext, [kick, snare, hihat])