
This is a snippet to retrieve a list of songs from a music CD in the CDROM Drive. This is used in conjunction with the AxWindowsMediaPlayer (wmp.dll). This snippet uses the IWMPPlaylist Interface to gain access to the playlist on the CD
Instructions: First, you need a reference to wmp.dll:
1. Click Projects > Add Reference
2. Click the COM tab
2. Scroll down and select Windows Media Player (wmp.dll)
Next you need a reference to AxWMPLib
The pass your player object to the method, and it will return a string array of the songs on the CD
//Namespace reference
using AxWMPLib;
/// <summary>
/// method to retrieve the songs from a music CD
/// </summary>
/// <param name="player">the WMP object that will be playing the songs</param>
/// <returns>string array or track names</returns>
public string[] GetTracksFromCD(AxWindowsMediaPlayer player)
{
// use the IWMPPlaylist Interface, which will give us
//access to the songs on the CD
WMPLib.IWMPPlaylist songs = player.cdromCollection.Item(0).Playlist;
// string array to hold the songs on the CD
String[] songList = new String[songs.count];
// loop through the songs on the CD
for (int i = 0; i < songs.count; i++)
{
//add each song to our string array using
//the get_Item Method of the AxWindowsMediaPlayer
songList[i] = songs.get_Item(i).name;
}
//return the songs
return songList;
}-Offline- |