Playlists
You can get existing playlists from the Network class or create a new one like so:
$playlist = $sonos->createPlaylist("Daniel Tompkins");
echo "{$playlist->getName()}\n";
# Changed my mind, delete the playlist from the network
$playlist->delete();
The Playlist class implements the Countable interface which means you can get the number of tracks by simply counting it:
$numberOfTracks = count($playlist);
# Or call the actual count method
$numberOfTracks = $playlist->count();
You can empty a playlist using the clear method:
$playlist->clear();
You can list all the tracks from a playlist:
$playlist = $sonos->getPlaylistByName("progmetal");
foreach ($playlist->getTracks() as $track) {
echo "* " . $track->getArtist() . " - " . $track->getTitle() . "\n";
}
Remove tracks from a playlist:
$progmetal = $sonos->getPlaylistByName("progmetal");
$remove = [];
foreach ($progmetal->getTracks() as $position => $track) {
if ($track->getArtist() === "protest the hero") {
$remove[] = $position;
}
}
if (count($remove) > 0) {
$progmetal->removeTracks($remove);
}