grass valley developers

Home > APIs > AppServer API > Examples > Asset Management > Asset User Data (metadata)

Asset User Data (metadata)

To Get and Set user data for an asset use the MediaMgr functions show in the examples below.

[C#]
// get a MediaMgr object
using ( IMediaMgr mediaMgr = connection.AppServer.CreateMediaMgr(appName) )
{
	int cookie = -1;
	try
	{
		// define an asset that we want to get & set userdata
		string clip = "edl/cmf//local/V:/default/Clip";

		// add userdate - string, integer, float, boolean, date
		mediaMgr.AddMetadata (clip, "SomeName", "SomeValue");
		mediaMgr.AddMetadata (clip, "SomeInteger", 5);
		mediaMgr.AddMetadata (clip, "SomeFloat", (float) 3.14);
		mediaMgr.AddMetadata (clip, "SomeBoolean", true);
		mediaMgr.AddMetadata (clip, "SomeDate", DateTime.Now);

		// select the user data for a clip
		int count = 0;
		cookie = mediaMgr.SelectMetadata (clip, ref count);
		Console.WriteLine("count = " + count);

		if ( count > 0 )
		{
			// get all user data tags
			string tags;
			mediaMgr.GetAllMetadataTags(out count, out tags);

			// print tags - see sample GetAllMetadataTags below class
			Console.WriteLine(tags);
			Console.WriteLine("-----------");

			// using GetXmlResults get all userdata for a clip in XML format
			int maxCount = 512; // loop thru all results in blocks of 512 lines
			// keep in 256 - 512 range for best performance

			int i = 0; // used to indicate where to start
			string xmlData = "";
			count = maxCount;

			// loop thru all results until done
			while (count == maxCount)
			{
				// get a block of user data and print it out
				mediaMgr.GetXmlResults(cookie, i * maxCount, maxCount, 
				ref count, out xmlData);
				Console.WriteLine(xmlData);

				// see sample GetXmlResults below class

				i++;
			}
		}

		// remove metadata - get ExtensionID from XML data from GetXmlResults call. 
		// hardcoded it here for simple example.
		string extensionID = "443c567a96394a679ccee6ecf17648b8";
		mediaMgr.RemoveMetadata (clip, extensionID);
	}
	catch (COMException ce)
	{
		Console.WriteLine("ERROR: caught COM Exception 0x{0:X}.", ce.ErrorCode);
		Console.WriteLine("Probably couldn't find metadata with that ExtensionID");
	}
	finally
	{
		if (cookie > -1)
		mediaMgr.CloseResults(cookie); 
	}
}
[C++]
// get a MediaMgr object
IMediaMgrPtr spMediaMgr;
hr = spAppServer->CreateMediaMgr(m_bstrAppName, &spMediaMgr);

// define an asset that we want to get & set userdata
_bstr_t bstrClip("edl/cmf//local/V:/default/Clip");

// add userdata - string, integer, float, boolean
spMediaMgr->AddMetadata(bstrClip, _bstr_t("SomeName"), _variant_t("SomeValue"));
spMediaMgr->AddMetadata(bstrClip, _bstr_t("SomeInteger"), _variant_t(5));
spMediaMgr->AddMetadata(bstrClip, _bstr_t("SomeFloat"), _variant_t((float) 3.14));
spMediaMgr->AddMetadata(bstrClip, _bstr_t("SomeBoolean"), _variant_t(TRUE));

// add userdata - date
COleDateTime oleDate(2008,3,17,12,15,0); 
_variant_t varDate;
varDate.date = oleDate;
varDate.vt = VT_DATE;
spMediaMgr->AddMetadata(bstrClip, _bstr_t("SomeDate"), varDate);

// select the user data for a clip
long count = 0;
long cookie;
spMediaMgr->SelectMetadata(bstrClip, &count, &cookie);

if ( count > 0 )
{
	// get all user data tags
	BSTR bstrTags;
	spMediaMgr->GetAllMetadataTags(&count, &bstrTags);
	CString sTags = bstrTags;

	printf("%s\n", sTags);
	printf("-----------\n");

	// using GetXmlResults get all userdata for a clip in XML format
	int maxCount = 512; // loop thru all results in blocks of 512 lines
	// keep in 256 - 512 range for performance

	int i = 0; // used to indicate where to start
	BSTR bstrXmlData;
	count = maxCount;

	// loop thru all results until done
	while (count == maxCount)
	{
		// get a block of user data and print it out
		spMediaMgr->GetXmlResults(cookie, i * maxCount, maxCount, 
		&count, &bstrXmlData);
		CString sXmlData = bstrXmlData;
		printf("%s\n", sXmlData); 

		i++;
	}

	// remove metadata - get ExtensionID from XML data from GetXmlResults call. 
	// hardcoded here for simple example.
	_bstr_t bstrExtensionID = _bstr_t("443c567a96394a679ccee6ecf17648b8");
	spMediaMgr->RemoveMetadata (bstrClip, bstrExtensionID);
}

The MediaMgr function GetAllMetadataTags() returns XML data that looks like this (for the above examples). See the "ns:Data" section towards the bottom for the data:


 

The MediaMgr functions SelectMetadata()and GetXmlResults() returns XML data that looks like this (for the above examples). See the "ns:Data" section towards the bottom for the data: