Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

cd-tray open or closed

Posted on 1998-07-23
5
Medium Priority
?
382 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 300 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 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