Share via


Windows Media Player 11 SDK Playlists and the PlaylistCollection Object 

Windows Media Player SDK banner art

Previous Next

Playlists and the PlaylistCollection Object

The PlaylistCollection object gives you access to playlists in the library and has methods for creating new, empty playlists and new playlists from metafiles.

Working with Existing Playlists

The PlaylistCollection**.getAll** and PlaylistCollection**.getByName** methods each return a PlaylistArray object, which can contain multiple playlists.

The PlaylistCollection**.getAll** method returns all of the existing playlists that are in the library. For example, you can call this method and then retrieve the playlists in the PlaylistArray object to determine whether a given playlist name has already been used, or to display all of the playlists to the user. The sample code in Playlist Attributes uses the getAll method.

The PlaylistCollection**.getByName** method returns all of the playlists with a given name. You can use this method to handle each of those playlists separately.

You can also use the getByName method to retrieve a unique playlist by name. In that case, the PlaylistArray object has only one element. The following C# example demonstrates this technique.

IWMPPlaylistArray PlayListArray;
IWMPPlaylist Playlist;
// Store the playlist named "BluesTest" in the array
PlayListArray = Player.playlistCollection.getByName("BluesTest");
// Retrieve the first playlist in the collection.
Playlist = PlaylistArray.item[0];

Working with New Playlists

You can use the PlaylistCollection**.newPlaylist** method to create a new, empty playlist. The method returns a reference to the new Playlist object. You can then call the Playlist**.appendItem** method to add media items to the playlist.

You can also create a new playlist based on a playlist metafile. First, pass the name of the playlist and the path to the metafile to the Player**.newPlaylist** method. That method returns a reference to the new Playlist object. Then, pass the new Playlist object to the PlaylistCollection**.importPlaylist** method to add it to the library.

Notice the difference between the PlaylistCollection**.newPlaylist** method and the Player**.newPlaylist** method. The PlaylistCollection method creates a new, empty playlist and adds it to the library. The Player method creates a new, populated Playlist object but does not add it to the library.

Throughout this topic, the Player object was defined in the following manner:

AxWMPLib.AxWindowsMediaPlayer Player;
using WMPLib;

The following C# example demonstrates importing a playlist from a metafile. The strPListName argument specifies the name of the new playlist. The strMetaFileName specifies the name of the metafile from which the playlist is imported.

private IWMPPlaylist importPlaylist(string strPlaylistName, string strMetaFileName)
{
    IWMPPlaylist  NewPlaylist;
    IWMPPlaylist  ImportPlaylist;

    NewPlaylist = Player.newPlaylist(strPlaylistName, strMetaFileName);
    ImportPlaylist = Player.playlistCollection.importPlaylist(NewPlaylist);

    return ImportPlaylist;
}

See Also

Previous Next