Solved

cd-tray open or closed

Posted on 1998-07-23
5
376 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
[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
  • 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

Independent Software Vendors: 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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

635 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