Skip to content

JIT Queue API ​

Provides Just-In-Time dynamic queue scheduling for network streaming and dynamic playback scenarios.

jitQueue ​

jitQueue.clear ​

Empty the buffer and return the session to idle.

This method takes no parameters.

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
const result = await fb2k.invoke('jitQueue.clear');

jitQueue.enqueueNext ​

Preload the next track into the buffer, in answer to jitQueue:needNext. Refused with NO_ACTIVE_ITEM unless a JIT session is playing or waiting for its next track.

ParameterTypeRequiredDescription
trackIdstringYesCaller-assigned identifier of the track. Must not be empty.
titlestringNoDisplay title. Default: "".
urlstringYesStream URL or file path. At most 2048 characters. Must not be empty.

Returns

FieldTypeDescription
trackIdstringThe identifier given.
bufferSizeintegerTracks in the buffer afterwards.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
await fb2k.invoke('jitQueue.enqueueNext', { trackId: 'track-2', url: 'https://example.com/next.mp3' });

jitQueue.getState ​

Report the JIT session state.

This method takes no parameters.

Returns

FieldTypeDescription
isActivebooleanWhether a JIT session is active.
state"Idle" | "Active" | "WaitingNext" | "Exhausted" | "Unknown"The session state.
currentTrackIdstringIdentifier of the playing track; empty when none.
nextTrackIdstringIdentifier of the buffered next track; empty when none.
bufferSizeintegerTracks in the buffer.
shadowPlaylistintegerIndex of the shadow playlist; -1 until a jitQueue.playNow or jitQueue.preloadBatch of this foobar2000 session creates or takes it over, even when one is left from an earlier session, and again after the playlist is removed, which also ends the JIT session. Stopping or clearing keeps the index of the emptied playlist.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
const result = await fb2k.invoke('jitQueue.getState');

jitQueue.notifyEmpty ​

Tell the host the page has no more tracks to offer; the session moves to Exhausted and jitQueue:listExhausted is emitted.

This method takes no parameters.

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
const result = await fb2k.invoke('jitQueue.notifyEmpty');

jitQueue.playNow ​

Start a new JIT session with this track: the buffer is cleared and playback begins. The host detects the URL kind itself (http(s):// streams, Windows or UNC paths are local). Tracks in the native playback queue are kept: when this track ends, foobar2000 plays them first and the JIT session ends.

ParameterTypeRequiredDescription
trackIdstringYesCaller-assigned identifier of the track, echoed in the session state and events. Must not be empty.
titlestringNoDisplay title. Default: "".
urlstringYesStream URL or file path. At most 2048 characters. Must not be empty.

Returns

FieldTypeDescription
trackIdstringThe identifier given.
shadowPlaylistintegerIndex of the shadow playlist, which the call creates or takes over when this session has none; -1 only if foobar2000 could not create it.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
await fb2k.invoke('jitQueue.playNow', { trackId: 'track-1', url: 'https://example.com/stream.mp3' });

jitQueue.preloadBatch ​

Insert a batch of tracks into the shadow playlist, starting playback from startIndex when the session is not already playing.

ParameterTypeRequiredDescription
urlsstring[]NoTrack URLs or path|subsong:N values. Entries longer than 2048 characters are dropped and counted in invalidCount; at most 10000 entries may remain.
startIndexintegerNoWhich entry to start playing from. At least 0. Default: 0.
replacebooleanNoEmpty the shadow playlist before inserting. false appends. Default: true.

Returns

FieldTypeDescription
tracksAddedintegerHow many tracks were inserted.
invalidCountintegerHow many entries were dropped for being too long.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

Preloads a batch of tracks into the JIT shadow playlist.

replace: true is the default and empties the shadow playlist before inserting, so pass false to add tracks without disturbing what is already queued. An entry that is not a string is refused with INVALID_PARAMS; entries longer than 2048 characters are dropped and counted in invalidCount rather than failing the call.

The 10000 limit is applied after those invalid entries are dropped, so it counts valid entries only. Exceeding it fails the whole batch — the list is never truncated — with INVALID_PARAMS (Batch exceeds maximum size (10000)) and no tracksAdded. An empty urls array or an out-of-range startIndex also fails with INVALID_PARAMS, carrying tracksAdded: 0 and invalidCount; a host-side failure while inserting is OPERATION_FAILED.

js
// replace the shadow playlist
await fb2k.invoke('jitQueue.preloadBatch', { urls, startIndex: 0 });
// append without disturbing playback
await fb2k.invoke('jitQueue.preloadBatch', { urls: moreUrls, replace: false });

jitQueue.skip ​

Skip to the next buffered track. When a buffered track follows the playing one, it plays that track and leaves the native playback queue untouched. Otherwise it acts as foobar2000's Next command, which plays the first track of the native playback queue when the queue is not empty. Refused with NO_ACTIVE_ITEM while no JIT session is active.

This method takes no parameters.

Returns

FieldTypeDescription
currentTrackIdstringIdentifier of the session's current track when the call returns. The skipped-to track has not started yet at that point, so this is still the track being skipped; the new one is reported by jitQueue:trackChanged.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
const result = await fb2k.invoke('jitQueue.skip');

jitQueue.stop ​

Stop playback, optionally keeping the buffer.

ParameterTypeRequiredDescription
clearBufferbooleanNoAlso empty the buffer. Default: true.

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
// stop and keep the preloaded buffer
await fb2k.invoke('jitQueue.stop', { clearBuffer: false });

JIT Queue events ​

These events are emitted while the JIT shadow playlist is maintained. Subscribe before issuing operations when the frontend needs to refill or observe that buffer.

EventMeaningPayload keys
jitQueue:needNextThe manager needs the next logical track.{ currentTrackId, reason }
jitQueue:trackChangedThe JIT current track changed.{ trackId, title }
jitQueue:listExhaustedNo further tracks are available — emitted on end of playback with an empty buffer, or after jitQueue.notifyEmpty.{ lastTrackId }
jitQueue:preloadCompleteA batch preload completed.{ count, startIndex, replace }
jitQueue:errorA JIT operation failed for a track.{ trackId, error } plus exactly one of url (streaming source) or path (local file)