IWMPMediaCollection::getByAlbum 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 getByAlbum method returns an IWMPPlaylist interface that provides access to media items from the specified album.

Syntax

public IWMPPlaylist getByAlbum(
  System.String bstrAlbum
);

Public Function getByAlbum( _
  ByVal bstrAlbum As System.String _
) As IWMPPlaylist
Implements IWMPMediaCollection.getByAlbum

Parameters

bstrAlbum [in]

The System.String that is the title of the album.

Return value

A WMPLib.IWMPPlaylist interface for the retrieved media items.

Remarks

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

There are two ways you ways you can retrieve an IWMPMediaCollection interface, and the behavior of the getByAlbum method depends on which of those two ways you use. If you retrieve the interface by calling AxWindowsMediaPlayer.mediaCollection, then the getByAlbum method returns all the media items in the library. However, if you retrieve the interface by calling IWMPLibrary.mediaCollection, then the getByAlbum method returns only the audio items in the library that belong to the specified album.

Examples

The following example uses getByAlbum to create a playlist of media items when the user clicks a button. The playlist contains items with the album specified by the user in a text box. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named player.

private void playAlbum_Click(object sender, System.EventArgs e)
{ 
    // ...Add code to ensure that the text box contains a valid value.
 
    // Retrieve the album title text that the user entered in the text box. 
    string album = getAlbum.Text;

    // Create the playlist using getByAlbum. 
    WMPLib.IWMPPlaylist pl = player.mediaCollection.getByAlbum(album);

    // Make the new playlist the current playlist. 
    player.currentPlaylist = pl;

    // Play the media in the current playlist. 
    player.Ctlcontrols.play();
}

Public Sub playAlbum_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles playAlbum.Click

    ' ...Add code to ensure that the text box contains a valid value.

    ' Retrieve the album title text that the user entered in the text box. 
    Dim album As String = getAlbum.Text

    ' Create the playlist using getByAlbum. 
    Dim pl As WMPLib.IWMPPlaylist = player.mediaCollection.getByAlbum(album)

    ' Make the new playlist the current playlist. 
    player.currentPlaylist = pl

    ' Play the media in the current playlist. 
    player.Ctlcontrols.play()

End Sub

Requirements

Requirement Value
Version
Windows Media Player 9 Series or later
Namespace
WMPLib
Assembly
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

See also

IWMPMediaCollection Interface (VB and C#)

IWMPPlaylist Interface (VB and C#)