Solved

Delphi Programming question

Posted on 1997-09-23
3
129 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
  • 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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