duncan3dc\Sonos\Queue::removeTracks PHP Method

removeTracks() public method

Remove tracks from the queue.
public removeTracks ( array $positions ) : boolean
$positions array The zero-based positions of the tracks to remove
return boolean
    public function removeTracks(array $positions)
    {
        $ranges = [];
        $key = 0;
        $last = -1;
        sort($positions);
        foreach ($positions as $position) {
            $position++;
            if ($last > -1) {
                if ($position === $last + 1) {
                    $ranges[$key]++;
                    $last = $position;
                    continue;
                }
            }
            $key = $position;
            $ranges[$key] = 1;
            $last = $position;
        }
        $offset = 0;
        foreach ($ranges as $position => $limit) {
            $position -= $offset;
            $data = $this->soap("AVTransport", "RemoveTrackRangeFromQueue", ["UpdateID" => $this->getUpdateID(), "StartingIndex" => $position, "NumberOfTracks" => $limit]);
            $this->updateId = $data;
            $offset += $limit;
        }
        return true;
    }