Skip to main content

AudioBufferQueueSourceNode

caution

Mobile only.

The AudioBufferQueueSourceNode is an AudioBufferBaseSourceNode which represents player that consists of many short buffers.

Constructor

BaseAudioContext.createBufferQueueSource()

Example

import React, { useRef } from 'react';
import {
AudioContext,
AudioBufferQueueSourceNode,
} from 'react-native-audio-api';

function App() {
const audioContextRef = useRef<AudioContext | null>(null);
if (!audioContextRef.current) {
audioContextRef.current = new AudioContext();
}
const audioBufferQueue = audioContextRef.current.createBufferQueueSource();
const buffer1 = ...; // Load your audio buffer here
const buffer2 = ...; // Load another audio buffer if needed
audioBufferQueue.enqueueBuffer(buffer1, false);
audioBufferQueue.enqueueBuffer(buffer2, true); // Last buffer should be marked as is
audioBufferQueue.connect(audioContextRef.current.destination);
audioBufferQueue.start(audioContextRef.current.currentTime);
}

Methods

enqueueBuffer

The above method lets you add another buffer to queue.

ParametersTypeDescription
bufferAudioBufferBuffer with next data.
isLastBufferbooleanBoolean indicating if it is a last buffer. Default value is false. Queue will stop after buffer marked as last will end.

Returns undefined.