Solved

cd-tray open or closed

Posted on 1998-07-23
5
341 Views
Last Modified: 2010-08-05
how can i check in delphi 2.0 if the cd-tray is open or closed?
how can i check if an audio-cd is inserted or a data-cd? checking for playable tracks doesn't work.
0
Comment
Question by:aperlitz
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1358559
Check out this component:
http://www.delphipages.com/edit/count.cfm?comID=367&Link=uploads%2FSystem%5FAPI%2FCDEvnt14%2Ezip
(all thanks go to ZifNab!)

ZifNab also found this pice of source for me once:

 Q) How can I tell if a given CD-ROM Drive contains an Audio CD?

 A) You can use the Windows API function GetDriveType() to test
   if the drive is a CD-ROM drive then use the Windows API function

 GetVolumeInformation() to test if the VolumeName is 'Audio CD'.
 Example:

 function IsAudioCD(Drive : char) : bool;
  var
    DrivePath : string;
    MaximumComponentLength : DWORD;
    FileSystemFlags : DWORD;
    VolumeName : string;
   begin
    Result := false;
    DrivePath := Drive + ':\';
    if GetDriveType(PChar(DrivePath)) <> DRIVE_CDROM then exit;
    SetLength(VolumeName, 64);
    GetVolumeInformation(PChar(DrivePath), PChar(VolumeName),                                                  Length(VolumeName),                                                    nil,                                                    MaximumComponentLength,                                                    FileSystemFlags, nil, 0);

 if lStrCmp(PChar(VolumeName),'Audio CD') = 0 then result := true;
 end;

   function PlayAudioCD(Drive : char) : bool;
   var
     mp : TMediaPlayer;
   begin
     result := false;
     Application.ProcessMessages;
     if not IsAudioCD(Drive) then exit;
     mp := TMediaPlayer.Create(nil);
     mp.Visible := false;
     mp.Parent := Application.MainForm;
     mp.Shareable := true;
     mp.DeviceType := dtCDAudio;
     mp.FileName := Drive + ':';
     mp.Shareable := true;
     mp.Open;
     Application.ProcessMessages;
     mp.Play;
     Application.ProcessMessages;
     mp.Close;
     Application.ProcessMessages;
     mp.free;
     result := true;
   end;

   procedure TForm1.Button1Click(Sender: TObject);
   begin
     if not PlayAudioCD('D') then
       ShowMessage('Not an Audio CD');
   end;

   Joe
   --
   Joe C. Hecht
   joehecht@gte.net

0
 
LVL 4

Accepted Solution

by:
BoRiS earned 100 total points
ID: 1358560
aperlitz

To open and close the CD tray use the mciSendCommand API call, from there you cn trap the true or false ... for example if false then cd tray is closed that kind of thing...

I think the API call goes something like this...

var
Tray: TMediaPlayer;
begin
mciSendCommand(Tray.DeviceID,
                            MCI_SET, MCI_SET_DOOR_CLOSED, 0);
                            Tray.Close;

Also check out the win32 help file have C code example that you can translate...

Matvey is totally correct in the code he gave you to check for audio CD's

(Matvey I hope I haven't intruded on the question...)

Later
BoRiS
0
 

Author Comment

by:aperlitz
ID: 1358561
the tip about checking for audio-cd's is perfect. works really great. but i need to know how i can check if the door is open or closed. i know, how to open and to close the door, but i want to let the user do this by clicking only one button. so the state of the door has to be checked when the user clicks the button. any suggestions about this? (i knew cdevents.pas before, but it didn't help me).
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1358562
aperlitz

The code I sent you will do it exactly that it closes the cd door if it's open to close it just cahnge the close stuff to open...

If you still need help leave your mail address and I'll send a example to you...

Later
BoRiS
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1358563
Well, Boris, both our comments weren't answeres. Why didn't you just leave the question open?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now