Search Tips Advanced Search |
| Delphi Graphics and Game Programming Exposed with DirectX 7.0 by John Ayres Wordware Publishing, Inc. ISBN: 1556226373 Pub Date: 12/01/99
Search this book:
Previous | Table of Contents | Next
When this function returns, if the dwReturn member is set to zero, there is no CD present in the drive, and the application should display an error message asking the user to insert the CD, repeating the check as necessary. If the dwReturn member is greater than zero, there is a CD in the drive, although it may not be the game’s CD. Each CD contains a unique identifying number that we can use to determine if it is the required CD. The example in Listing 9-11 demonstrates how to extract this identifying number. Set the Time Format Like MIDI, we must inform the MCI subsystem as to the timing format used for playback. Red Book Audio is timed by tracks, minutes, seconds, and frames, where there are 75 frames per second. We will use a variable of type TMCI_Set_Parms, setting its dwTimeFormat member to MCI_FORMAT_TMSF to indicate this unusual timing format. For example:
      {set the time format for the CD audio device}

      SetParms.dwTimeFormat := MCI_FORMAT_TMSF;

      MCISendCommand(MCIDeviceID, MCI_SET, MCI_WAIT or MCI_SET_TIME_FORMAT,

                     Longint(@SetParms));
Retrieve the Number of Tracks and Their Length While it’s not absolutely necessary to retrieve the number of tracks on a CD, you do need to record the length of each track. More specifically, you must record the length of the very last track for reasons that are explained below. For the purposes of our example, however, we will record the number of tracks on the CD and the length of each so they may be displayed by our CD player example. We make use of another TMCI_Status_Parms variable, setting its dwItem member to MCI_STATUS_NUMBER_OF_TRACKS to indicate we wish to retrieve the number of tracks. Once this is accomplished, we can then set dwTrack to a specific track number (we’ll iterate through each track) and the dwItem member to MCI_STATUS_LENGTH, indicating we wish to retrieve its length. For example:
      {retrieve the number of tracks on the CD}

      StatusParms.dwItem := MCI_STATUS_NUMBER_OF_TRACKS ;

      MCISendCommand(MCIDeviceID, MCI_STATUS, MCI_WAIT or MCI_STATUS_ITEM,

                     LongInt(@StatusParms));

      NumTracks := StatusParms.dwReturn;

      {for each track, indicate its length}

      for iCount := 1 to NumTracks do

      begin

        StatusParms.dwTrack := iCount;

        StatusParms.dwItem := MCI_STATUS_LENGTH;

        MCISendCommand(MCIDeviceID, MCI_STATUS, MCI_WAIT or MCI_STATUS_ITEM or

                       MCI_TRACK, LongInt(@StatusParms));

       .

       .

       .

    end;
Commence Playback Once the CD device is opened, and we have determined that a CD does in fact exist, we can play a track. For this, we will need a variable of the type TMCI_Play_Parms. However, we must make use of the dwFrom and dwTo members of this structure in order to indicate the exact desired track to play. Because of the unusual timing format, we must use the MCI_MAKE_TMSF function to encode an appropriate starting and ending play position. Playing a single track is relatively simple, as we can specify a starting track with an ending track one greater than the starting track. For example:
    PlayParms.dwFrom := MCI_MAKE_TMSF(1, 0, 0, 0);

    PlayParms.dwTo := MCI_MAKE_TMSF(2, 0, 0, 0);

    MCISendCommand(MCIDeviceID, MCI_PLAY, MCI_FROM or MCI_TO, Longint(@PlayParms));
This indicates that we wish to play track one in its entirety. However, this technique will not work on the last track, since there is not another track beyond it (and setting the from member to a value one greater than the number of tracks on a CD results in an error). Therefore, you must specify the exact length of the track when playing the very last one. This is why we recorded all of the track lengths earlier. We’ll see an implementation of this in Listing 9-11. Stop Playback Before another CD track can be played, the currently playing track must be stopped. This is accomplished by simply calling the MCISendCommand function with a command message of MCI_STOP. For example:
    MCISendCommand(MCIDeviceID, MCI_STOP, MCI_WAIT, 0);
Close the Device As with MIDI, the MCI device must be closed and released by calling the MCISendCommand with a command message of MCI_CLOSE when the application terminates. The MCI device ID must be passed in to the first parameter, but the last two parameters are unused and should be set to zero. The following example implements the discussed steps in order to play back Red Book Audio data from a CD.
Previous | Table of Contents | Next

Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.