Solved

cd-tray open or closed

Posted on 1998-07-23
5
348 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

22 Experts available now in Live!

Get 1:1 Help Now