protected function addUris(array $tracks, int $position = null)
    {
        if ($position === null) {
            $position = $this->getNextPosition();
        }

        /**
         * It seems like adding over 16 tracks at once causes the request to fail with error 402.
         * I guess at this point Sonos decides it's more efficient to lookup the contents
         * by their container, and the call fails because we don't have a container for these tracks.
         */
        $chunks = array_chunk($tracks, 16);

        foreach ($chunks as $chunk) {
            $uris = "";
            $metaData = "";
            $first = true;
            foreach ($chunk as $track) {
                if ($first) {
                    $first = false;
                } else {
                    $uris .= " ";
                    $metaData .= " ";
                }

                $uris .= $track->getUri();
                $metaData .= $track->getMetaData();
            }

            $numberOfTracks = count($chunk);

            $data = $this->soap("AVTransport", "AddMultipleURIsToQueue", [
                "UpdateID"                          =>  0,
                "NumberOfURIs"                      =>  $numberOfTracks,
                "EnqueuedURIs"                      =>  $uris,
                "EnqueuedURIsMetaData"              =>  $metaData,
                "DesiredFirstTrackNumberEnqueued"   =>  $position,
                "EnqueueAsNext"                     =>  0,
            ]);
            $this->updateId = $data["NewUpdateID"];

            $position += $numberOfTracks;
        }
    }
protected function addUris(array $tracks, int $position = null)
    {
        if ($position === null) {
            $position = $this->getNextPosition();
        }

        /**
         * It seems like adding over 16 tracks at once causes the request to fail with error 402.
         * I guess at this point Sonos decides it's more efficient to lookup the contents
         * by their container, and the call fails because we don't have a container for these tracks.
         */
        $chunks = array_chunk($tracks, 16);

        foreach ($chunks as $chunk) {
            $uris = "";
            $metaData = "";
            $first = true;
            foreach ($chunk as $track) {
                if ($first) {
                    $first = false;
                } else {
                    $uris .= " ";
                    $metaData .= " ";
                }

                $uris .= $track->getUri();
                $metaData .= $track->getMetaData();
            }

            $numberOfTracks = count($chunk);

            $data = $this->soap("AVTransport", "AddMultipleURIsToQueue", [
                "UpdateID"                          =>  0,
                "NumberOfURIs"                      =>  $numberOfTracks,
                "EnqueuedURIs"                      =>  $uris,
                "EnqueuedURIsMetaData"              =>  $metaData,
                "DesiredFirstTrackNumberEnqueued"   =>  $position,
                "EnqueueAsNext"                     =>  0,
            ]);
            $this->updateId = $data["NewUpdateID"];

            $position += $numberOfTracks;
        }
    }
protected function addUris ( array $ tracks , int $ position = null ) { if ( $ position === null ) { $ position = $ this -> getNextPosition ( ) ; } /**
         * It seems like adding over 16 tracks at once causes the request to fail with error 402.
         * I guess at this point Sonos decides it's more efficient to lookup the contents
         * by their container, and the call fails because we don't have a container for these tracks.
         */ $ chunks = array_chunk ( $ tracks , 16 ) ; foreach ( $ chunks as $ chunk ) { $ uris = "" ; $ metaData = "" ; $ first = true ; foreach ( $ chunk as $ track ) { if ( $ first ) { $ first = false ; } else { $ uris .= " " ; $ metaData .= " " ; } $ uris .= $ track -> getUri ( ) ; $ metaData .= $ track -> getMetaData ( ) ; } $ numberOfTracks = count ( $ chunk ) ; $ data = $ this -> soap ( "AVTransport" , "AddMultipleURIsToQueue" , [ "UpdateID" => 0 , "NumberOfURIs" => $ numberOfTracks , "EnqueuedURIs" => $ uris , "EnqueuedURIsMetaData" => $ metaData , "DesiredFirstTrackNumberEnqueued" => $ position , "EnqueueAsNext" => 0 , ] ) ; $ this -> updateId = $ data [ "NewUpdateID" ] ; $ position += $ numberOfTracks ; } }
Add multiple uris to the queue.

@param UriInterface[] $tracks The track to add
@param int $position The position to insert the track in the queue (zero-based),
by default the track will be added to the end of the queue

@return void
Add multiple uris to the queue .