Click here for a
complete OFFICIAL
list of ALL MCI
Commands
                    

Home
AVI (Audio Visual)
WAV (Sound/Audio)
MIDI(Sequence/Music)
CD (CD Audio)
Download
Links
FAQ
Email
CD Audio Compact Disc Music
    CD Audio tracks can be played in Windows

If you have Visual Basic 4.0 or newer then copy and paste this code into a module. (eg. module1.bas)
Declare Function mciSendString Lib "winmm.dll" Alias _
    "mciSendStringA" (ByVal lpstrCommand As String, ByVal _
    lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _
    hwndCallback As Long) As Long


If you have Visual Basic 3.0 then copy and paste this code into a module. (eg. module1.bas)

Declare Function mciSendString Lib "mmsystem" (ByVal lpstrCommand$, ByVal lpstrReturnStr As Any, ByVal wReturnLen%, ByVal hCallBack%) As Long


OPEN
     We must OPEN a CD Audio disk before we can do anything to with it. All of the other MCI commands listed on this web page require that the OPEN command to be used first, otherwise they will not work. The type of multimedia file we want to use is cdaudio and the alias name that we will use to refer to the AVI file is cd1 (Although we can use any alias name you desire, such as "Mycd", "cd2", "john1", etc... , we'll use cd1 for easy reference in the examples that follow).
  i = mciSendString("open cdaudio alias cd1", 0&, 0, 0)
OPEN Multiple CDs
     A lot of people are installing a second CD drive into their computers, due to the lower prices of CDRs and CDRWs. The sample below will open the CD in drive f:\. Notice the we used cd2 as the alias. This will prevent the first CD from following commands intended for this second CD.
 
  i = mciSendString("open  f:\  type cdaudio alias cd2", 0&, 0, 0)
Format (Time or Tracks)
     In order to select tracks or specific points in time on an Audio CD, you must first determine what you are working with.


TIME FORMAT CODE...
  i = mciSendString("set cd1 time  format tmsf", 0&, 0, 0)
NOTE:
   tmsf returns 00:00:00:00 OR Tracks:minutes:seconds:milliseconds

TRACK FORMAT CODE...
  i = mciSendString("set cd1 time format milliseconds", 0, 0, 0)
                    OR
  i = mciSendString("set cd1 time format ms", 0, 0, 0)  
NOTE:
   ms or milliseconds returns milliseconds

Play
     When an Audio CD is open, we can play it. The keyword in this command is PLAY.
    i = mciSendString("play cd1", 0&, 0, 0)
Play from...
     You don't have to start playing a CD file from the beginning. You can start anywhere. This example starts at position 4 and plays to the end. If you set the format to TRACKS, then this example will start at track 4, otherwise it will start at 4 milliseconds.
  i = mciSendString("play cd from 4", 0&, 0, 0)
Play from to...
     Perhaps you want to hear a certain track ot part of a track. You will need code to play a specific portion or parameter of the CD. This example requires that you set the format to milliseconds beforehand.
  i = mciSendString("play cd from 2001 to 3400", 0&, 0, 0)
Pause
     While an CD is being played, you can pause it. Use the resume command to resume playing.
  i = mciSendString("pause cd", 0&, 0, 0)
Stop...
     While a CD is being played, you can stop it. Use the play command to start playing it again.
  i = mciSendString("stop cd", 0&, 0, 0)
TIP: You can use the code below to play a CD that has been stopped. This gives the user the "rewind illusion" that once a CD is stopped (much like a DVD), it will start from the beginning when played again. This also distinguishes the difference from the pause command.
      i = mciSendString("play cd from 0", 0&, 0, 0)
Seek
     Any position within CD can be set by using the seek command. The example below sets the CD to position to 1000 milliseconds.
  i = mciSendString("seek cd to 1000", 0&, 0, 0)
Eject (open/close door)
     Your CD drive most likely will have the capability to automatically eject the CD and close the CD door.


OPEN DOOR
  i = mciSendString("set cd door open wait", 0&, 0, 0)
CLOSE DOOR
  i = mciSendString("set cd door closed wait", 0&, 0, 0)
Close...
     Perhaps this is the most important MCI command code for your project. You must close the CD file (unless you need it open for another program). Leaving it open could cause problems with Windows. The opened CD will remain open, known as "being used", or "hanging".
  i = mciSendString("close cd", 0&, 0, 0)
Audio ON/OFF
     You can turn the audio CD on or off with the sample codes below.
  i = mciSendString("set cd audio all off", 0&, 0, 0)
  i = mciSendString("set cd audio all on", 0&, 0, 0)
  i = mciSendString("set cd audio left off", 0&, 0, 0)
  i = mciSendString("set cd audio left on", 0&, 0, 0)
  i = mciSendString("set cd audio right off", 0&, 0, 0)
  i = mciSendString("set cd audio right on", 0&, 0, 0)
1