Solved

Delphi Programming question

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

10 Experts available now in Live!

Get 1:1 Help Now