Share via


IWMPPlaylistCollection::getByName 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 getByName method returns a IWMPPlaylistArray interface that provides access to playlists with the specified name, if any exist.

Syntax

public IWMPPlaylistArray getByName(
  System.String bstrName
);

Public Function getByName( _
  ByVal bstrName As System.String _
) As IWMPPlaylistArray
Implements IWMPPlaylistCollection.getByName

Parameters

bstrName [in]

A System.String that is the name of the playlist.

Return value

A WMPLib.IWMPPlaylistArray interface for the retrieved array of playlists.

Remarks

Use IWMPPlaylistArray.count to determine whether a playlist exists. If count is zero, the array is empty.

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

Examples

The following example uses getByName to check the playlist collection for a playlist named "Favorites -- 4 and 5 star rated". If a playlist by that name exists, getByName sets it as the current playlist. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named player.

// Get the count of the playlists named "Favorites -- 4 and 5 star rated".
int checkit = player.playlistCollection.getByName("Favorites -- 4 and 5 star rated").count;

// Since duplicate playlist names are allowed, the count returned
// will be either zero (no playlist) or greater than zero (playlist exists).
if (checkit > 0)
{
    // Retrieve a playlist array containing "Favorites -- 4 and 5 star rated".
    // Assume that there is only one playlist with that name, and assign it to the 
    // current playlist.
    player.currentPlaylist = player.playlistCollection.getByName("Favorites -- 4 and 5 star rated").Item(0);
}

'  Get the count of the playlists named "Favorites -- 4 and 5 star rated".
Dim checkit As Integer = player.playlistCollection.getByName("Favorites -- 4 and 5 star rated").count

'  Since duplicate playlist names are allowed, the count returned
'  will be either zero (no playlist) or greater than zero (playlist exists).
If (checkit > 0) Then

    '  Retrieve a playlist array object containing "Favorites -- 4 and 5 star rated".
    '  Assume that there is only one playlist with that name, and assign it to the 
    '  current playlist.
    player.currentPlaylist = player.playlistCollection.getByName("Favorites -- 4 and 5 star rated").Item(0)

End If

Requirements

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

See also

IWMPPlaylistArray Interface (VB and C#)

IWMPPlaylistArray.count (VB and C#)

IWMPPlaylistCollection Interface (VB and C#)