Queue
When playing tracks from your library or other music services you’ll be using the queue.
You can check if a controller is currently using a queue, make it use the queue, and then get the queue like so:
if (!$controller->isUsingQueue()) {
$controller->useQueue();
}
$queue = $controller->getQueue();
The Queue class implements the Countable interface which means you can get the number of tracks by simply counting it:
$numberOfTracks = count($queue);
# Or call the actual count method
$numberOfTracks = $queue->count();
You can empty a queue using the clear method:
$queue->clear();
Add all the tracks from a playlist to the queue:
$playlist = $sonos->getPlaylistByName("protest the hero");
$tracks = $playlist->getTracks();
$queue->addTracks($tracks);
Remove tracks from the queue:
$remove = [];
foreach ($queue->getTracks() as $position => $track) {
if ($track->getArtist() === "pomegranate tiger") {
$remove[] = $position;
}
}
if (count($remove) > 0) {
$queue->removeTracks($remove);
}