Skip to content

features/queue

useActiveTrack()

ts
function useActiveTrack(): Track | undefined;

Hook that returns the current active track and updates when it changes.

Returns

Track | undefined

The current active track or undefined


getActiveTrack()

ts
function getActiveTrack(): Track | undefined;

Gets the active track or undefined if there is no current track.

Returns

Track | undefined


onActiveTrackChanged

ts
const onActiveTrackChanged: NativeUpdatedValue<PlaybackActiveTrackChangedEvent>;

Subscribes to active track change events.

Param

Called when the active track changes

Returns

Cleanup function to unsubscribe


PlaybackActiveTrackChangedEvent

Event data for when the active track changes.

Properties

PropertyTypeDescription
lastIndex?numberThe index of previously active track.
lastTrack?TrackThe previously active track or undefined when there wasn't a previously active track.
lastPositionnumberThe position of the previously active track in seconds.
index?numberThe newly active track index or undefined if there is no longer an active track.
track?TrackThe newly active track or undefined if there is no longer an active track.

getActiveTrackIndex()

ts
function getActiveTrackIndex(): number | undefined;

Gets the index of the active track in the queue or undefined if there is no current track.

Returns

number | undefined


add()

Call Signature

ts
function add(tracks, insertBeforeIndex?): void;

Adds one or more tracks to the queue.

Parameters

ParameterTypeDescription
tracksTrack[]The tracks to add to the queue.
insertBeforeIndex?number(Optional) The index to insert the tracks before. By default the tracks will be added to the end of the queue.

Returns

void

Call Signature

ts
function add(track, insertBeforeIndex?): void;

Adds a track to the queue.

Parameters

ParameterTypeDescription
trackTrackThe track to add to the queue.
insertBeforeIndex?number(Optional) The index to insert the track before. By default the track will be added to the end of the queue.

Returns

void


load()

ts
function load(track): void;

Replaces the current track or loads the track as the first in the queue.

Parameters

ParameterTypeDescription
trackTrackThe track to load.

Returns

void


move()

ts
function move(fromIndex, toIndex): void;

Move a track within the queue.

Parameters

ParameterTypeDescription
fromIndexnumberThe index of the track to be moved.
toIndexnumberThe index to move the track to. If the index is larger than the size of the queue, then the track is moved to the end of the queue.

Returns

void


useQueue()

ts
function useQueue(): Track[];

Hook that returns the current queue and updates when it changes.

Returns

Track[]

The current queue


getQueue()

ts
function getQueue(): Track[];

Gets the whole queue.

Returns

Track[]


setQueue()

ts
function setQueue(tracks): void;

Sets the queue.

Parameters

ParameterTypeDescription
tracksTrack[]The tracks to set as the queue.

Returns

void


onQueueEnded

ts
const onQueueEnded: NativeUpdatedValue<PlaybackQueueEndedEvent>;

Subscribes to playback queue ended events.

Param

Called when playback has paused due to reaching the end of the queue

Returns

Cleanup function to unsubscribe


onQueueChanged

ts
const onQueueChanged: NativeUpdatedValue<Track[]>;

Subscribes to queue change events. Called when tracks are added, removed, reordered, or when track metadata changes.

Param

Called with the updated queue

Returns

Cleanup function to unsubscribe


PlaybackQueueEndedEvent

Event data for when the playback queue has ended.

Properties

PropertyTypeDescription
tracknumberThe index of the active track when the playback queue ended.
positionnumberThe playback position in seconds of the active track when the playback queue ended.

remove()

Call Signature

ts
function remove(indexes): void;

Removes multiple tracks from the queue by their indexes.

If the current track is removed, the next track will activated. If the current track was the last track in the queue, the first track will be activated.

Parameters

ParameterTypeDescription
indexesnumber[]The indexes of the tracks to be removed.

Returns

void

Call Signature

ts
function remove(index): void;

Removes a track from the queue by its index.

If the current track is removed, the next track will activated. If the current track was the last track in the queue, the first track will be activated.

Parameters

ParameterTypeDescription
indexnumberThe index of the track to be removed.

Returns

void


removeUpcomingTracks()

ts
function removeUpcomingTracks(): void;

Clears any upcoming tracks from the queue.

Returns

void


useRepeatMode()

ts
function useRepeatMode(): RepeatMode;

Hook that returns the current repeat mode and updates when it changes.

Returns

RepeatMode

The current repeat mode


getRepeatMode()

ts
function getRepeatMode(): RepeatMode;

Gets the current repeat mode.

Returns

RepeatMode


setRepeatMode()

ts
function setRepeatMode(repeatMode): void;

Sets the repeat mode.

Parameters

ParameterTypeDescription
repeatModeRepeatModeThe repeat mode to set

Returns

void


onRepeatModeChanged

ts
const onRepeatModeChanged: NativeUpdatedValue<RepeatModeChangedEvent>;

Subscribes to repeat mode changes.

Param

Called when repeat mode changes

Returns

Cleanup function to unsubscribe


RepeatMode

ts
type RepeatMode = "off" | "track" | "queue";

RepeatMode options:

  • 'off': Playback stops when the last track in the queue has finished playing.
  • 'track': Repeats the current track infinitely during ongoing playback.
  • 'queue': Repeats the entire queue infinitely.

RepeatModeChangedEvent

Properties

PropertyTypeDescription
repeatModeRepeatModeThe new repeat mode

useShuffle()

ts
function useShuffle(): boolean;

Hook that returns whether shuffle mode is enabled and updates when it changes.

Returns

boolean

Whether shuffle mode is enabled


getShuffle()

ts
function getShuffle(): boolean;

Gets whether shuffle mode is enabled.

Returns

boolean


setShuffle()

ts
function setShuffle(enabled): void;

Sets whether shuffle mode is enabled. When enabled, tracks play in a randomized order.

Parameters

ParameterTypeDescription
enabledbooleanWhether to enable shuffle mode

Returns

void


toggleShuffle()

ts
function toggleShuffle(): void;

Toggles shuffle mode on/off.

Returns

void


onShuffleChanged

ts
const onShuffleChanged: NativeUpdatedValue<boolean>;

Subscribes to shuffle mode changes.

Param

Called when shuffle mode changes

Returns

Cleanup function to unsubscribe


skip()

ts
function skip(index, initialPosition?): void;

Skips to a track in the queue.

Parameters

ParameterTypeDescription
indexnumberThe index of the track to skip to.
initialPosition?number(Optional) The initial position to seek to in seconds.

Returns

void


skipToNext()

ts
function skipToNext(initialPosition?): void;

Skips to the next track in the queue.

Parameters

ParameterTypeDescription
initialPosition?number(Optional) The initial position to seek to in seconds.

Returns

void


skipToPrevious()

ts
function skipToPrevious(initialPosition?): void;

Skips to the previous track in the queue.

Parameters

ParameterTypeDescription
initialPosition?number(Optional) The initial position to seek to in seconds.

Returns

void


getTrack()

ts
function getTrack(index): Track | undefined;

Gets a track object from the queue.

Parameters

ParameterTypeDescription
indexnumberThe index of the track.

Returns

Track | undefined

The track object or undefined if there isn't a track object at that index.