Solved

Delphi Programming question

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 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