Queue

Control playback order, manipulate the queue, and react to track changes in Nuclear.

Queue API for Plugins

The Queue API gives plugins full control over Nuclear's playback queue. Add tracks, reorder items, control navigation, and subscribe to queue changes—all from your plugin code.

circle-info

Access the queue via NuclearAPI.Queue.* in your plugin's lifecycle hooks. All queue operations are asynchronous and return Promises.


Core concepts

Queue structure

The queue is a list of items with a pointer to the current playback position:

type Queue = {
  items: QueueItem[];        // Ordered list of tracks
  currentIndex: number;      // Position of currently playing item (0-based)
  repeatMode: RepeatMode;    // 'off' | 'all' | 'one'
  shuffleEnabled: boolean;   // Random navigation when true
};

Queue items

Each item in the queue has its own unique ID and tracks its own state:

Status lifecycle:

  • idle — Item is in queue but hasn't been played yet

  • loading — Stream resolution in progress

  • success — Stream resolved and ready for playback

  • error — All streams failed or playback error occurred

Repeat modes

  • off — Stop at the end of the queue

  • all — Loop back to the beginning when reaching the end

  • one — Repeat the current track (handled by playback service, not queue navigation)

Shuffle

When shuffleEnabled is true, goToNext() and goToPrevious() pick random indices instead of sequential ones. The algorithm avoids repeating the same track twice in a row.


Quick start


Reference


Best practices

  • Use subscriptions for reactive featuressubscribe() for queue-wide changes, subscribeToCurrentItem() for playback tracking

  • Batch operations — All add/remove methods accept arrays; use them instead of looping

  • Clean up subscriptions — Always unsubscribe in onDisable to prevent memory leaks

  • Check queue state before navigation — Use getQueue() to verify bounds before calling goToIndex()

  • Respect user intent — Don't manipulate shuffle/repeat modes unless your plugin explicitly manages playback


Troubleshooting

Symptom
Cause
Fix

"Queue host not available"

Called before plugin loaded or outside runtime

Move to onLoad/onEnable lifecycle hooks

Added tracks disappear on restart

Not using the API, modifying state directly

Only use api.Queue.* methods, never manipulate queue state directly

goToId() does nothing

ID doesn't exist in queue

Verify ID exists by checking queue.items first

Last updated