IWMPMediaCollection::getAttributeStringCollection-Methode

[Das dieser Seite zugeordnete Feature Windows Medienwiedergabe SDK ist ein Legacyfeature. Es wurde von MediaPlayer ersetzt. MediaPlayer wurde für Windows 10 und Windows 11 optimiert. Microsoft empfiehlt dringend, nach Möglichkeit für neuen Code MediaPlayer anstelle von Windows Medienwiedergabe SDK zu verwenden. Microsoft schlägt vor, vorhandenen Code, der die Legacy-APIs verwendet, um nach Möglichkeit die neuen APIs zu verwenden.]

Die getAttributeStringCollection-Methode gibt eine IWMPStringCollection-Schnittstelle zurück, die den Satz aller Werte für ein angegebenes Attribut innerhalb eines Medientyps darstellt.

Syntax

public IWMPStringCollection getAttributeStringCollection(
  System.String bstrAttribute,
  System.String bstrMediaType
);

Public Function getAttributeStringCollection( _
  ByVal bstrAttribute As System.String, _
  ByVal bstrMediaType As System.String _
) As IWMPStringCollection
Implements IWMPMediaCollection.getAttributeStringCollection

Parameter

bstrAttribute [in]

Ein System.String-Attribut , für das die Werte abgerufen werden.

bstrMediaType [in]

Ein System.String - das ist der Medientyp, für den die Werte abgerufen werden.

Rückgabewert

Eine WMPLib.IWMPStringCollection-Schnittstelle für die abgerufenen Werte.

Bemerkungen

Bevor Sie diese Methode aufrufen, benötigen Sie Lesezugriff auf die Bibliothek. Weitere Informationen finden Sie unter Bibliothekszugriff.

Informationen zu den von Windows Medienwiedergabe unterstützten Attributen finden Sie in der Attributreferenz.

Beispiele

Im folgenden Beispiel wird getAttributeStringCollection verwendet, um eine Liste von Werten anzuzeigen, die einem bestimmten Attribut für Audioelemente in der Mediensammlung entsprechen. Ein Listenfeld ermöglicht es dem Benutzer, ein Attribut wie Künstler, Genre oder Album auszuwählen, und ein mehrzeiliges Textfeld zeigt das Ergebnis an. Das AxWMPLib.AxWindowsMediaPlayer-Objekt wird durch die Variable player dargestellt.

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

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

    &#39; Retrieve the attribute type from the ListBox
    Dim lb As System.Windows.Forms.ListBox = sender
    Dim attributeType As String = lb.SelectedItem

    &#39; Get an interface to the mediaCollection.  
    Dim library As WMPLib.IWMPMediaCollection2 = player.mediaCollection

    &#39; Get an interface to the string collection for the attribute type the user selects.
    Dim all As WMPLib.IWMPStringCollection2 = library.getAttributeStringCollection(attributeType, &quot;Audio&quot;)

    &#39; Clear the text box of previous results.
    attributeValues.Clear()

    &#39; Create an array to hold the attribute values.
    Dim attributeArray(all.count) As String

    &#39; Loop through the string collection.
    For i As Integer = 0 To (all.count - 1)

        &#39; Store the items in the array.
        attributeArray(i) = all.Item(i)

    Next i

    &#39; Display the items in the text box.
    attributeValues.Lines = attributeArray

End Sub

Anforderungen

Anforderung Wert
Version
Windows Medienwiedergabe Serie 9 oder höher
Namespace
WMPLib
Assembly
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

Siehe auch

IWMPMediaCollection-Schnittstelle (VB und C#)

IWMPStringCollection-Schnittstelle (VB und C#)