Queue¶
Queue is a thread-safe audio queue with built-in history tracking, loop modes, shuffle, and async waiting.
Each Player has two queues: player.queue (main) and player.auto_queue (AutoPlay recommendations).
Guide
See the Queue Guide for usage patterns, loop modes, and history examples.
Queue ¶
The default custom revvlink Queue designed specifically for :class:revvlink.Player.
Player implements this queue by default. You can access it via revvlink.Player.queue.
str(queue)A string representation of this queue.repr(queue)The official string representation of this queue.if queueBool check whether this queue has items or not.queue(track)Put a track in the queue.len(queue)The amount of tracks in the queue.queue[1]Peek at an item in the queue. Does not change the queue.for item in queueIterate over the queue.if item in queueCheck whether a specific track is in the queue.queue[1] = trackSet a track in the queue at a specific index.del queue[1]Delete a track from the queue at a specific index.reversed(queue)Return a reversed iterator of the queue.Attributes:
| Name | Type | Description |
|---|---|---|
history |
:class:`revvlink.Queue`
|
A queue of tracks that have been added to history. Tracks are added to history when they are played. |
mode
property
writable
¶
The current :class:~revvlink.QueueMode of the queue.
This property can be set with any :class:~revvlink.QueueMode.
Returns:
| Type | Description |
|---|---|
class:`~revvlink.QueueMode`
|
The current queue mode. |
history
property
¶
The history queue containing previously played tracks.
Returns:
| Type | Description |
|---|---|
class:`Queue` | None
|
The history queue, or |
count
property
¶
The queue member count.
Returns:
| Type | Description |
|---|---|
int
|
The amount of tracks in the queue. |
is_empty
property
¶
Whether the queue has no members.
Returns:
| Type | Description |
|---|---|
bool
|
Whether the queue is empty. |
loaded
property
writable
¶
The currently loaded track that will repeat when the queue is set
to :attr:revvlink.QueueMode.loop.
This track will be retrieved when using :meth:revvlink.Queue.get if
the queue is in loop mode. You can unload the track by setting this
property to None or by using :meth:revvlink.Player.skip with
force=True.
Setting this property to a new :class:revvlink.Playable will replace
the currently loaded track, but will not add it to the queue; or
history until the track is played.
Returns:
| Type | Description |
|---|---|
class:`revvlink.Playable` | None
|
The currently loaded track or |
Raises:
| Type | Description |
|---|---|
TypeError
|
The track was not a :class: |
get ¶
Retrieve a track from the left side of the queue. E.g. the first.
This method does not block.
Due to the way the queue loop works, this method will return the same track if the queue is in loop mode. You can use revvlink.Player.skip with force=True to skip the current track.
Do NOT use this method to remove tracks from the queue, use either:
del queue[index]revvlink.Queue.removerevvlink.Queue.delete
Returns:
| Type | Description |
|---|---|
class:`revvlink.Playable`
|
The track retrieved from the queue. |
Raises:
| Type | Description |
|---|---|
QueueEmpty
|
The queue was empty when retrieving a track. |
get_at ¶
Retrieve a track from the queue at a given index.
Due to the way the queue loop works, this method will load the retrieved track for looping.
Do NOT use this method to remove tracks from the queue, use either:
del queue[index]revvlink.Queue.removerevvlink.Queue.delete
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index of the track to get. |
required |
Returns:
| Type | Description |
|---|---|
class:`revvlink.Playable`
|
The track retrieved from the queue. |
Raises:
| Type | Description |
|---|---|
QueueEmpty
|
The queue was empty when retrieving a track. |
IndexError
|
The index was out of range for the current queue. |
put_at ¶
Put a track into the queue at a given index.
This method doesn't replace the track at the index but rather inserts one there, similar to a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index to put the track at. |
required |
value
|
Playable
|
The track to put. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
The track was not a :class: |
get_wait
async
¶
This method returns the first :class:revvlink.Playable if one is present or
waits indefinitely until one is.
This method is asynchronous.
Returns:
| Type | Description |
|---|---|
class:`revvlink.Playable`
|
The track retrieved from the queue. |
put ¶
Put an item into the end of the queue.
Accepts a :class:revvlink.Playable, :class:revvlink.Playlist or
list[:class:revvlink.Playable].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
list[Playable] | Playable | Playlist
|
list[:class: |
required |
atomic
|
bool
|
Whether the items should be inserted atomically. If set to |
True
|
Returns:
| Type | Description |
|---|---|
int
|
The number of tracks added to the queue. |
put_wait
async
¶
Put an item or items into the end of the queue asynchronously.
Accepts a :class:revvlink.Playable or :class:revvlink.Playlist
or list[:class:revvlink.Playable].
This method implements a lock to preserve insert order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
list[Playable] | Playable | Playlist
|
list[:class: |
required |
atomic
|
bool
|
Whether the items should be inserted atomically. If set to |
True
|
Returns:
| Type | Description |
|---|---|
int
|
The number of tracks added to the queue. |
delete ¶
Method to delete an item in the queue by index.
Raises:
| Type | Description |
|---|---|
IndexError
|
No track exists at this index. |
Examples:
# Deletes the track at index 1 (The second track).
queue.delete(1)
peek ¶
Method to peek at an item in the queue by index.
This does not change the queue or remove the item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index to peek at. Defaults to |
0
|
Returns:
| Type | Description |
|---|---|
class:`revvlink.Playable`
|
The track at the given index. |
Raises:
| Type | Description |
|---|---|
QueueEmpty
|
There are no items currently in this queue. |
IndexError
|
No track exists at the given index. |
swap ¶
Swap two items in the queue by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first
|
int
|
The first index to swap with. |
required |
second
|
int
|
The second index to swap with. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
IndexError
|
No track exists at the given index. |
Example
# Swap the first and second tracks in the queue.
queue.swap(0, 1)
index ¶
Return the index of the first occurence of a :class:revvlink.Playable in the queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Playable
|
The item to search the index for. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The index of the item in the queue. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The item was not found in the queue. |
shuffle ¶
Randomly shuffle all tracks currently in the queue.
This method shuffles the queue in place.
Example
player.queue.shuffle()
clear ¶
Remove all tracks from the queue.
This does not clear the history queue. To clear history, use queue.history.clear().
Example
player.queue.clear()
copy ¶
Create a shallow copy of this queue.
Returns:
| Type | Description |
|---|---|
class:`Queue`
|
The copied queue. |
reset ¶
Reset the queue and history to their default states.
This clears all tracks, history, and cancels any pending waiters.
This will cancel any waiting futures on the queue. E.g. revvlink.Queue.get_wait.
remove ¶
Remove a specific track from the queue up to a given count or all instances.
This method starts from the left hand side of the queue E.g. the beginning.
Setting count to <= 0 is equivalent to setting it to 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Playable
|
The item to remove from the queue. |
required |
count
|
int | None
|
The amount of times to remove the item from the queue. Defaults to |
1
|
Returns:
| Type | Description |
|---|---|
int
|
The amount of times the item was removed from the queue. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The item was not found in the queue. |