MediaAttributeCollection Object
Represents a collection of MediaAttribute objects.
XAML | See Remarks |
Scripting |
See Remarks.
|
Properties
Methods
Clear, Equals, FindName, GetHost, GetItem, GetItemByName, GetValue, Insert, Remove, RemoveAt, SetValue
Remarks
Each MediaAttribute in the collection represents a Name-Value pair that corresponds to an xml tag in the ASX file the Source property of the MediaElement is set to.
If the Source property of the MediaElement is not set, is set to a media file rather than an ASX file, or is checked prior to MediaOpened, the collection is empty. Do not attempt to script to this collection until the MediaOpened event is raised.
This collection has an Add method, but it is not usable. Generally you must treat the collection as a one-time copy of a read-only collection that reflects the ASX file, and you should not modify its contents. Other collection methods such as Remove are also not particularly useful for this reason, you would only be modifying a copy. The most useful method of this collection is the specialized method GetItemByName.
MediaAttributeCollection technically does have a XAML usage and can be instantiated as a XAML object element. However, this usage does not have a practical application. The useful collection of MediaAttribute objects is contained within the metadata of an ASX source that is loaded by a MediaElement. You can get this collection as the Attributes property through scripting, and this collection is not valid until the MediaOpened event is raised. Specifying MediaAttribute values in XAML ahead of time as part of a MediaElement will only result in that entire Attributes value being erased and replaced as soon as a media source is loaded by the MediaElement.
Examples
The following JavaScript example shows how to retrieve a MediaAttribute by name from the Attributes property of a MediaElement that has a Source property set to an ASX playlist file. The Name and Value properties of the MediaAttribute is then displayed.
JavaScript |
---|
function onMediaOpened(sender, args) { // Variable to hold the MediaAttribute. var attribute; // Get the MediaAttribute named Title try { var attributesCollection = sender.Attributes; attribute = attributesCollection.getItemByName("Title"); } catch(errorObj) { alert(errorObj.message); } // Display the Value of the MediaAttribute if(attribute != null) { alert("The title of the track is: " + attribute.value); } } |