Share via


Windows Media Player 11 SDK IWMPMediaCollection.getAttributeStringCollection (VB and C#) 

Windows Media Player SDK banner art

Previous Next

IWMPMediaCollection.getAttributeStringCollection (VB and C#)

The getAttributeStringCollection method returns an IWMPStringCollection interface that represents the set of all values for a specified attribute within a media type.

  

Parameters

bstrAttribute

A System.String that is the attribute for which the values are retrieved.

bstrMediaType

A System.String that is the media type for which the values are retrieved.

Return Value

A WMPLib.IWMPStringCollection interface for the retrieved values.

Remarks

Before calling this method, you must have read access to the library. For more information, see Library Access.

For information about the attributes supported by Windows Media Player, see the Attribute Reference.

Example Code

The following example uses getAttributeStringCollection to display a list of values that correspond to a particular attribute for audio items in the media collection. A list box allows the user to select an attribute, such as Artist, Genre, or Album and a multi-line text box displays the result. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named player.

  
Public Sub audioAttributes_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles audioAttributes.SelectedIndexChanged

    ' Retrieve the attribute type from the ListBox
    Dim lb As System.Windows.Forms.ListBox = sender
    Dim attributeType As String = lb.SelectedItem

    ' Get an interface to the mediaCollection.  
    Dim library As WMPLib.IWMPMediaCollection2 = player.mediaCollection

    ' Get an interface to the string collection for the attribute type the user selects.
    Dim all As WMPLib.IWMPStringCollection2 = library.getAttributeStringCollection(attributeType, "Audio")

    ' Clear the text box of previous results.
    attributeValues.Clear()

    ' Create an array to hold the attribute values.
    Dim attributeArray(all.count) As String

    ' Loop through the string collection.
    For i As Integer = 0 To (all.count - 1)

        ' Store the items in the array.
        attributeArray(i) = all.Item(i)

    Next i

    ' Display the items in the text box.
    attributeValues.Lines = attributeArray

End Sub

FakePre-e04bb7e3c2004b689187fcf43a925fb3-9daf257bf1284e2aac29b63a1189ed8c

private void audioAttributes_OnSelectedIndexChanged(object sender, System.EventArgs e)
{
    // Retrieve the attribute type from the ListBox
    string attributeType = (string)((System.Windows.Forms.ListBox)sender).SelectedItem;

    // Get an interface to the mediaCollection.  
    WMPLib.IWMPMediaCollection2 library = (WMPLib.IWMPMediaCollection2)player.mediaCollection;

    // Get an interface to the string collection for the attribute type the user selects.
    WMPLib.IWMPStringCollection2 all = (WMPLib.IWMPStringCollection2)library.getAttributeStringCollection(attributeType, "Audio");

    // Clear the text box of previous results.
    attributeValues.Clear();

    // Create an array to hold the attribute values.
    string[] attributeArray = new string[all.count];
    
    // Loop through the string collection.
    for (int i = 0; i < all.count; i++)
    {
        // Store the items in the array.
        attributeArray[i] = all.Item(i);
    }

    // Display the items in the text box.
    attributeValues.Lines = attributeArray;
}

Requirements

Version: Windows Media Player 9 Series or later

Namespace: WMPLib

Assembly: Interop.WMPLib.dll (automatically generated by Visual Studio)

See Also

Previous Next