Compartir a través de


MediaAttribute

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents an attribute from an entry in an ASX file.

Syntax Notes

See Remarks.

Managed Equivalent

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

Remarks

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.

Example

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.
    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);
    }
}