How to get Audio CD info using CDDB servers |
|
There are three situations in which obtaining information about an Audio CD may be required:
When an Audio CD is physically available inside the CD drive
In this situation there is the possibility to perform CDDB queries to servers distributed around the world.
CDDB (which stands for Compact Disc Database) is a database for software applications to look up CD information over the Internet. This is performed by a client which calculates a (nearly) unique disc ID and then queries the database. As a result, the client is able to display the artist name, CD title, track list and some additional information.
The first needed task, in order to retrieve CDDB information about an audio CD, is to verify the availability of an open Internet connection and then to request the list of available servers: this operation is performed through a call to the CddbRequestServersList method: due to the fact that retrieving information from the Internet can be a lengthy operation, this call will return immediately and, when the list of servers will be available, the container application is notified through the CallbackForCdDrivesEvents delegate which is invoked with the nEvent parameter set to EV_CDDB_SERVERS_AVAIL: at this point it will be possible requesting each CDDB server's friendly name using the CddbGetServerName method. Note that if the target PC is running behind a proxy, you have the possibility to set the proxy details through the CddbSetProxyDetails method.
The second needed task is to have an audio CD inserted inside a CD drive on the target machine: this will allow calling the CddbRequestAlbumInfo method that, after calculating the audio CD's Unique Identification Number, will send a request to the server of choice: also in this case, retrieving information from the Internet can be a lengthy operation, so this call will return immediately; when the CD album information will be available, the container application is notified through the CallbackForCdDrivesEvents delegate which is invoked with the nEvent parameter set to EV_CDDB_ALBUM_INFO_AVAIL: at this point it will be possible requesting specific album information through the CddbGetAlbumInfo method, enumerating CD tracks calling the GetCdNumTracks method and obtain the title of each single track through the CddbGetTrackTitle method.
When CD album information are requested and obtained through a call to the CddbRequestAlbumInfo method, the control automatically performs a search of the same Audio CD in order to obtain cover pictures (also know as CD cover art) of the Audio CD: these pictures are usually of three different sizes: Small (thumbnail), Medium and Large. When this information is found, the control notifies the container application about their availability through the CallbackForCdDrivesEvents delegate which is invoked with the nEvent parameter set to:
• | EV_CD_COVER_URLS_AVAIL: notifies that the URL pointing to a certain CD cover picture is available and can be obtained through a call to the GetCdCoverPictureURL method. |
• | EV_CD_COVER_SMALL_FILE_AVAIL, EV_CD_COVER_MEDIUM_FILE_AVAIL and EV_CD_COVER_LARGE_FILE_AVAIL: notify that a certain CD cover picture has been downloaded and is now available locally: the local absolute pathname of the picture can at this point be obtained through a call to the GetCdCoverPictureFile method. It's important to note that the downloaded picture files are temporarily stored inside the system defined "Temp" directory and are automatically deleted when the container application is closed. |
When an Audio CD is not physically available inside the CD drive but a song with relevant tag info is loaded into a player
After having loaded a song into a player through the LoadSound or similar methods, you can call the CdInfoCreate method which instructs the control to parse eventual tag information stored inside the song: if the control should succeed in obtaining the name of the author and the title of the album it will be possible to get a number of information about this Audio CD through the following methods:
• | CdInfoGet allows obtaining the URL of pictures representing the CD cover, the year when the CD was published, the URL of the purchase page and the number of tracks available inside the Audio CD. |
• | CdTrackTitleGet allows obtaining the title of each single track stored inside the Audio CD |
• | CdCoverPictureFileGet allows obtaining the local pathname of pictures representing the CD cover: these graphic files are automatically downloaded as temporary files when the Audio CD is found. |
• | CdNavigateToUrl allows opening the system default Internet browser and navigating to the purchase URL of the Audio CD. |
When an Audio CD is not physically available inside the CD drive but author's name and album's title are known.
Differently from situations described above, where the artist name and the album title are obtained through a CDDB server or by looking into tag information stored inside the song file, in this situation the control can search information about an Audio CD through the CdRequestAlbumInfo method and, when requested information become available, the container application is notified through the CallbackForCdDrivesEvents delegate which is invoked with the nEvent parameter set to:
• | EV_CDDB_ALBUM_INFO_AVAIL: notifies that information about the album is available and can be retrieved through the CddbGetAlbumInfo method; at the same time also the number of tracks and respective titles are retrieved and can be enumerated calling the GetCdNumTracks method (passing -1 to its nCdDriveIndex parameter) in conjunction with the CddbGetTrackTitle method. |
• | EV_CD_COVER_URLS_AVAIL: notifies that the URL pointing to a certain CD cover picture is available and can be obtained through a call to the GetCdCoverPictureURL method. |
• | EV_CD_COVER_SMALL_FILE_AVAIL, EV_CD_COVER_MEDIUM_FILE_AVAIL and EV_CD_COVER_LARGE_FILE_AVAIL: notify that a certain CD cover picture has been downloaded and is now available locally: the local absolute pathname of the picture can at this point be obtained through a call to the GetCdCoverPictureFile method. It's important to note that the downloaded picture files are temporarily stored inside the system defined "Temp" directory and are automatically deleted when the container application is closed. |
A sample of access to CDDB resources in Visual C# and Visual Basic.NET can be found inside the following sample installed with the product's setup package:
- SoundInfo
- CdPlayerWithCddb