IWMPMediaCollection::getByAttribute method
[The feature associated with this page, Windows Media Player SDK, is a legacy feature. It has been superseded by MediaPlayer. MediaPlayer has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer instead of Windows Media Player SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]
The getByAttribute method returns an IWMPPlaylist interface that corresponds to the specified attribute having the specified value.
Syntax
public IWMPPlaylist getByAttribute(
System.String bstrAttribute,
System.String bstrValue
);
Public Function getByAttribute( _
ByVal bstrAttribute As System.String, _
ByVal bstrValue As System.String _
) As IWMPPlaylist
Implements IWMPMediaCollection.getByAttribute
Parameters
-
bstrAttribute [in]
-
The System.String that is the specified attribute.
-
bstrValue [in]
-
The System.String that is the specified value.
Return value
A WMPLib.IWMPPlaylist interface for the retrieved media items.
Remarks
This method can be used to create a generic query for media items that match a value for an attribute in the library. This is useful in the case of user-defined attributes. If the attribute does not exist, an error will result.
You can use this method to retrieve all of the media items of a specific type. Use the attribute name MediaType and one of the following values.
Value | Description |
---|---|
audio | Music and other audio-only items |
other | Other items, such as an .asf file or the URL of a stream. |
photo | Photo items. Requires Windows Media Player 10. |
playlist | Playlists represented as media items. |
radio | Radio station items. Not used by Windows Media Player 10. |
video | Video items. |
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.
There are two ways you ways you can retrieve an IWMPMediaCollection interface, and the behavior of the getByAttribute method depends on which of those two ways you use. If you retrieve the interface by calling AxWindowsMediaPlayer.mediaCollection, then the getByAttribute method returns all the media items in the library. However, if you retrieve the interface by calling IWMPLibrary.mediaCollection, then the getByAttribute method returns only the audio items in the library that have the specified attribute and value.
Examples
The following code example uses getByAttribute to play all content from the library by the artist named Triode 48. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named player.
// Get an interface to a playlist that contains media items by a particular artist.
WMPLib.IWMPPlaylist pl = player.mediaCollection.getByAttribute("Artist", "Triode 48");
// Make the new playlist the current one.
player.currentPlaylist = pl;
// Play the media items in the current playlist.
player.Ctlcontrols.play();
' Get an interface to a playlist that contains media items by a particular artist.
Dim pl As WMPLib.IWMPPlaylist = player.mediaCollection.getByAttribute("Artist", "Triode 48")
' Make the new playlist the current one.
player.currentPlaylist = pl
' Play the media items in the current playlist.
player.Ctlcontrols.play()
Requirements
Requirement | Value |
---|---|
Version |
Windows Media Player 9 Series or later |
Namespace |
WMPLib |
Assembly |
|