Listing more than 1000 assets with the PHP SDK for Azure Media Services


To get the list of assets from Azure Media Services in the PHP SDK you use the getAssetList() function to get a list of video assets.  If you have more than 1000 assets the getAssetList() function will only return the first 1000.  Azure Media Services limits the number of results returned for performance reasons.  The way to get the full list is to page through the list 1000 assets at a time.  The .NET SDK has this ability built in, but unfortunately the PHP SDK does not.  We can add a new function in the REST proxy to do this.
The getAssetList() call is fed through the REST proxy.  To make this work we have to add a new function to the REST proxy that specifically handles this.  This is modeled on the getAssetList function.  This is in MediaServicesRestProxy.php. 
/**
 * Get paged asset list starting at skip value
 *
 * @return array of Models\Asset
 */
public function getAssetListPage($skipStart)
{
    $propertyList = $this->_getEntityList("Assets()?".'$skip='.$skipStart);
    $result       = array();
 
    foreach ($propertyList as $properties) {
        $result[] = Asset::createFromOptions($properties);
    }
 
    return $result;
}
 
When calling the getAssetListPage function, use an index value for the next 1000 similar to getAssetListPage(1000).
I'd like to thank Dhanendran Rajagopal for help with the code.
Comments (0)

Skip to main content