Solved

Delphi Programming question

Posted on 1997-09-23
3
134 Views
Last Modified: 2010-05-18
How can I set a timeout value for the Delph 2.0 TMediaPlayer component to detect that there is no CD in a CD ROM drive?  As I try right now, my program doesn't time out; it just apparently stops running while it waits and I must Ctrl-Alt-Del and end the task to continue.
0
Comment
Question by:slepnir
[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
3 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 0 total points
ID: 1346049
Hi slepnir,

Why need detection? TMediaplayer itself doesn't start playing when there is no CD in the drive, even if you've pushed the play button. See what I mean and put a TMediaplayer (CDPlayer) on the Form (Form1). Thanks to this, you don't need to worry if there is a CD in the drive.

procedure TForm1.FormCreate(Sender: TObject);
begin
 try
  CDPLayer.DeviceType := dtCDAudio;
  CDPlayer.open;
 except
  on EMCIDeviceError do begin
   MessageDlg('Error Initialising CD Player. Program will now exit.', mtError, [mbOk], 0);
   Application.Terminate;
  end;
 end;
end;

Need an example of a whole CD-player, just ask and I'll send it to you. Hope this is the solution for your problem. Otherwise please explain the problem more precisely.
0
 

Author Comment

by:slepnir
ID: 1346050
Thanks for your quick answer, ZifNab.  However, it seems that I have some substandard device drivers for my CD ROM drive.  The exception handler of the code you gave me never gets executed when there's no CD in the drive!  In fact, when there's no CD in the drive, I can't even make any invalid calls!  Every method of TMediaPlayer returns a number, albeit invalid since there's no CD.

My problem was that the MediaPlayer seemingly went into an infinite wait.  I assumed the CD Player wasn't timing out.  What I didn't realize until I looked at your example was that my code involving the MediaPlayer went into a loop of 4206248 iterations, as I was iterating over the number of tracks!

Yes, for some reason, my CD ROM drivers seem to indicate that there are 4206248 tracks on any non-existant CD!

If only the 'open' method were virtual and I could write a descendent to raise an exception on a call to 'open' a CD with more than 99 tracks.  Oh, well.  I guess it's back to the old if..then error handling for this job.

thanks
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1346051
Hi slepnir,

about exception handler -> it is only executed when there is no cd-rom drive on the computer!

Try this for your tracks :

procedure TForm1.GetCDTotals;
{ This method gets the total time and tracks of the CD and displays them }
var
 l : longint;
begin
 CDPlayer.TimeFormat := tfTMSF;
 l := CDPlayer.Length;
 TotalTracks := mci_Tmsf_Track(CDPlayer.Tracks);
 TotalLengthM := mci_msf_Minute(l);
 TotallengthS := mci_msf_Second(l);
 
 TotTrkLabel.Caption := TrackNumToString(TotalTracks);
 TotLenLabel.Caption := IntToStr(TotalLength)+ 'm'+ ' '+
                        IntToStr(TotalLength) + 's';

 DiskDoneGauge.MaxValue := (TotalLength*60)+TotalLengthS;
end;

This code comes from a book. I can still give you the whole code of the CDPlayer example, if you want.

Have fun,
c.u. ZifNab;
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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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