Méthode IWMPMediaCollection::getAttributeStringCollection
[La fonctionnalité associée à cette page, Lecteur multimédia Windows SDK, est une fonctionnalité héritée. Il a été remplacé par MediaPlayer. MediaPlayer a été optimisé pour Windows 10 et Windows 11. Microsoft recommande vivement que le nouveau code utilise MediaPlayer au lieu de Lecteur multimédia Windows SDK, lorsque cela est possible. Microsoft suggère que le code existant qui utilise les API héritées soit réécrit pour utiliser les nouvelles API si possible.]
La méthode getAttributeStringCollection renvoie une interface IWMPStringCollection qui représente l’ensemble de toutes les valeurs d’un attribut spécifié dans un type de média.
Syntaxe
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
Paramètres
-
bstrAttribute [in]
-
System.String qui est l’attribut pour lequel les valeurs sont récupérées.
-
bstrMediaType [in]
-
System.String qui est le type de média pour lequel les valeurs sont récupérées.
Valeur retournée
Interface WMPLib.IWMPStringCollection pour les valeurs récupérées.
Notes
Avant d’appeler cette méthode, vous devez disposer d’un accès en lecture à la bibliothèque. Pour plus d’informations, consultez Accès à la bibliothèque.
Pour plus d’informations sur les attributs pris en charge par Lecteur multimédia Windows, consultez la référence des attributs.
Exemples
L’exemple suivant utilise getAttributeStringCollection pour afficher une liste de valeurs qui correspondent à un attribut particulier pour les éléments audio de la collection multimédia. Une zone de liste permet à l’utilisateur de sélectionner un attribut, tel que Artiste, Genre ou Album, et une zone de texte multiligne affiche le résultat. L’objet AxWMPLib.AxWindowsMediaPlayer est représenté par la variable nommée player.
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
' 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
Configuration requise
Condition requise | Valeur |
---|---|
Version |
série Lecteur multimédia Windows 9 ou ultérieure |
Espace de noms |
WMPLib |
Assembly |
|
Voir aussi
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour