Solved

CD routines

Posted on 2001-06-27
7
232 Views
Last Modified: 2010-04-06
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)
0
Comment
Question by:duke_n
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6231516
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...
0
 
LVL 1

Author Comment

by:duke_n
ID: 6231595
And what If I wanna do that(eject/retract) to the second/third/../twentieth CD?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6231805
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;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
ID: 6232115
Ok here is is:

uses MMSystem;

const
  DRIVE = 'G:';

procedure TForm1.GetNumberOfTracksClick(Sender: TObject);
var mciOpenParms: TMCI_Open_Parms;
    mciStatusParms: TMCI_Status_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciOpenParms.lpstrElementName := DRIVE;
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, 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;

procedure TForm1.OpenCDClick(Sender: TObject);
var mciOpenParms: TMCI_Open_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciOpenParms.lpstrElementName := DRIVE;
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Cardinal(@mciOpenParms));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;

procedure TForm1.CloseCDClick(Sender: TObject);
var mciOpenParms: TMCI_Open_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciOpenParms.lpstrElementName := DRIVE;
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Cardinal(@mciOpenParms));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;
0
 
LVL 1

Author Comment

by:duke_n
ID: 6232207
exceptional.
thank you very much.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6232217
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;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6232221
Thanks  :o)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
When I am typing into a TEdit last word repeats 7 176
find a node in VST 2 92
LAN or WAN ? 11 120
Browsing a TTreeView in Delphi 5 48
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question