Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
.gif)
| Previous | Next |
IWMPMediaCollection.getByAttribute (VB and C#)
The getByAttribute method returns an IWMPPlaylist interface that corresponds to the specified attribute having the specified value.
Parameters
bstrAttribute
The System.String that is the specified attribute.
bstrValue
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.
Example Code
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.
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()
FakePre-9d2603b67ec1452bb8aadb8210ba94ee-fac4c3cba6ad41488923408c6e12c42d
// 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();
Requirements
Version: Windows Media Player 9 Series or later
Namespace: WMPLib
Assembly: Interop.WMPLib.dll (automatically generated by Visual Studio)
See Also
- IWMPMediaCollection Interface (VB and C#)
- IWMPPlaylist Interface (VB and C#)
- IWMPPlaylistCollection.getAll (VB and C#)
| Previous | Next |