Skip to content

createAudioPlayer

function createAudioPlayer<Context>(options): Promise<AudioPlayer<ReturnType<Context["createGain"]>>>;

Defined in: audio-player.ts:476

Create an audio player on context: it loads the jitter buffer’s worklet once per context, so it resolves after that. Connect player.output yourself.

const context = new AudioContext({ sampleRate: 48_000, latencyHint: 'interactive' });
const player = await createAudioPlayer({ context });
player.output.connect(context.destination);
const clock = createPlayoutClock({ targetLatencyUs: AUDIO_ONLY_TARGET_LATENCY_US });
const input = player.addInput({ clock, decoderConfig: audioDecoderConfigFromTrack(audioTrack) });
const reader = createFrameReader(createFrameSequencer({ clock, grouping: 'frame' }), { onFrame: input.push });
subscriber.subscribe({ namespace, track: 'audio' }, { ...reader, onError });
Type Parameter
Context extends AudioPlayerContext
Parameter Type
options AudioPlayerOptions<Context>

Promise<AudioPlayer<ReturnType<Context["createGain"]>>>