grass valley developers

Home > APIs > AppServer API > Examples > Asset Management > Get a List of Clips

Get a List of Clips

The sample code below shows how you can get a list of clips in a bin and then get properties of those clips. The way you do it is:

1. Call EnumerateAssets to create a list of the clips in a bin
2. Query the list for the clip properties you want (click here for a list of asset properties you can query).
3. Print the results.

[C#]
// create a mediamgr object
IMediaMgr mediaMgr = iappServer.CreateMediaMgr(appName);

// enumerate the assets in the v:\default bin
int count = 0;
int cookie = mediaMgr.EnumerateAssets("V:", "default", ref count);
 
// let's query for 3 properties of the clip: the name, video compression type,
// and the length
string query = "name+videoCompressionType+lengthstr";
 
// Other properties you can query:
// "uri", "name", "assettype", "created", "modified", "attributes1", 
// "attributes2", "videoformat", "videocompressiontype", "firsttimecodemask", 
// "lengthstr", "maxlength", "markin", "markout", "markinstr", "markoutstr", 
// "dropframe", "locked", "hidef"
// for other properties search the guide for "Asset properties" 

// Let's only get info on the first 100 clips in the bin
int maxCount = 100;
object dataObj = null;

// Now, let's query for the results we want: 
// query it for the properties we setup above, 
// start with the 0th element, 
// go up to a max of 100 clips
// capture the actual number of clips we're getting data back from,
// and return the results in a data object
mediaMgr.GetResultProperty( cookie, query, 0, maxCount, out count, out dataObj);

Console.WriteLine("Found " + count + " clips in V:\\default\\");

// GetResultProperty for clip data returns a 2 dimensional array
// - the first dimension represents the clip
// - the second dimension represents the properties of the clip

// so let's cast the dataobj to a clip array first
object[] clipArray = (object[]) dataObj; 

// loop thru each clip
foreach (object clip in clipArray)
{
 // then cast the clip object to an array of properties for each clip
 object[] propertyArray = (object[]) clip;
 
 // and finally print out the clip properties for each clip
 Console.WriteLine("Clip: {0} Created: {1} Length: {2}", 
 propertyArray[0], propertyArray[1], propertyArray[2]);
}

// make sure that you close the results after enumerating volumes, bins, or assets.
// if you don't, you will run out of database selectors!
mediaMgr.CloseResults(cookie);
mediaMgr.Dispose();
[C++]
// create a mediamgr object
IMediaMgrPtr spMediaMgr;
HRESULT hr = spAppServer->CreateMediaMgr(m_bstrAppName, &spMediaMgr);

// enumerate the assets in the v:\default bin
long cookie;
long count = 0;
BSTR bstrXmlData = NULL; // must set this to NULL!

spMediaMgr->EnumerateAssets(_bstr_t("V:"), _bstr_t("default"), &count, &cookie);

// let's query for 3 properties of the clip: the name, video compression type,
// and the length
_bstr_t sQuery("name+videoCompressionType+lengthstr");

// Other properties you can query:
// "uri", "name", "assettype", "created", "modified", "attributes1", 
// "attributes2", "videoformat", "videocompressiontype", "firsttimecodemask", 
// "lengthstr", "maxlength", "markin", "markout", "markinstr", "markoutstr", 
// "dropframe", "locked", "hidef"
// for other properties search the guide for "Asset properties" 

// Let's only get info on the first 100 clips in the bin
int maxCount = 100;

// Now, let's query for the results we want: 
// query it for the properties we setup above, 
// start with the 0th element, 
// go up to a max of 100 clips
// capture the actual number of clips we're getting data back from,
// and return the results in a data object
VARIANT varResult;
spMediaMgr->GetResultProperty( cookie, sQuery, 0, maxCount, &count, &varResult);

printf("Found %d clips in V:\\default\\\n", count);

// create a safe array for the clips
SAFEARRAY *pClipArray = varResult.parray;
VARIANT *pVar = NULL;
long arrClipIndex[1];

// get the first clip
arrClipIndex[0] = 0;
SafeArrayPtrOfIndex(pClipArray, arrClipIndex, (void **)&pVar);

// create a safe array for the clip's properties
SAFEARRAY* pPropertyArray = pVar->parray;
long arrPropertyIndex[1];

// get the first property
arrPropertyIndex[0] = 0;
SafeArrayPtrOfIndex(pPropertyArray, arrPropertyIndex, (void **)&pVar);
CString sName = pVar->bstrVal;

// get the second property
arrPropertyIndex[0] = 1;
SafeArrayPtrOfIndex(pPropertyArray, arrPropertyIndex, (void **)&pVar);
CString sVideoCompressionType = pVar->bstrVal;

// get the third property
arrPropertyIndex[0] = 2;
SafeArrayPtrOfIndex(pPropertyArray, arrPropertyIndex, (void **)&pVar);
CString sLength = pVar->bstrVal;

printf("Clip name: %s video compression type: %s length: %s\n\n", sName, sVideoCompressionType, sLength);

// etc...

// make sure that you close the results after enumerating volumes, bins, or assets.
// if you don't, you will run out of database selectors!
spMediaMgr->CloseResults(cookie);