Link to home
Start Free TrialLog in
Avatar of duke_n
duke_n

asked on

CD routines

I need 3 routines: Eject, Retract and Count tracks(without using MediaPlayer).

I know there is an mcisendstring or something like that but it does not handle the situation of having more than one CD drive(for example if someone has CD and CDR)
Avatar of Epsylon
Epsylon

uses MMSystem;


// to open
mciSendString('Set cdaudio door open wait', nil, 0, handle);

// yo close
mciSendString('Set cdaudio door closed wait', nil, 0, handle);


I have no idea how to count the tracks...
Avatar of duke_n

ASKER

And what If I wanna do that(eject/retract) to the second/third/../twentieth CD?
Here's roughly how to get the number of tracks:

var mciOpenParms: TMCI_Open_Parms;
    mciStatusParms: TMCI_Status_Parms;
    mciSetParms: TMCI_Set_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE, Cardinal(@mciOpenParms));
  mciStatusParms.dwItem := MCI_STATUS_NUMBER_OF_TRACKS;
  if mciSendCommand(mciOpenParms.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@mciStatusParms)) = 0 then
    ShowMessage(IntToStr(mciStatusParms.dwReturn));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of duke_n

ASKER

exceptional.
thank you very much.
Here is how to find CDROM drives:

procedure ListDrives(Strings: TStrings);
const BufSize = 256;
var
  Buffer: PChar;
  P: PChar;
begin
  GetMem(Buffer, BufSize);
  try
    Strings.BeginUpdate;
    try
      Strings.Clear;
      if GetLogicalDriveStrings(BufSize, Buffer) <> 0 then
      begin
        P := Buffer;
        while P^ <> #0 do
        begin
          if GetDriveType(PChar(P)) = DRIVE_CDROM then
            Strings.Add(P);
          Inc(P, StrLen(P) + 1);
        end;
      end;
    finally
      Strings.EndUpdate;
    end;
  finally
    FreeMem(Buffer, BufSize);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListDrives(ListBox1.Items);
end;
Thanks  :o)