Represents an attribute from an entry in an ASX file.

See Remarks.

Media attributes are entries in a Dictionary<TKey, TValue> that can be accessed through the Attributes property.

Technically, you can use MediaAttribute in XAML and instantiate it as a XAML object element. However, MediaAttribute instantiation in XAML does not have any practical application. The useful collection of MediaAttribute objects is contained in the metadata of each given source that is loaded by a MediaElement object. You can get this collection as the Attributes property through scripting, and this collection is not valid until the MediaOpened event is raised. Specifying a MediaAttribute 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.

The following JavaScript example shows how to retrieve the Attributes property of a MediaElement that has a Source property set to an ASX playlist file. The example iterates through the retrieved MediaAttributeCollection object and displays the Name and Value properties of each MediaAttribute object.

function onMediaOpened(sender, args) {
    // Create the variable to hold the MediaAttribute.
    var attribute;
    // Get the MediaAttribute that is named Title.
        var attributesCollection = sender.Attributes;
        attribute = attributesCollection.getItemByName("Title");
    // Display the value of the MediaAttribute.
    if(attribute != null)
      alert("The title of the track is: " + attribute.value);

Community Additions