Solved

Delphi Programming question

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

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

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 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…
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 …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

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

16 Experts available now in Live!

Get 1:1 Help Now