Link to home
Start Free TrialLog in
Avatar of lecossois
lecossois

asked on

Can't play audio CDs with TMediaPlayer

I have a bit of a strange problem.  I can't play audio CDs with TMediaplayer.  I can do it with the CD player that comes with Win95, or with WinAmp, but not with Delphi.  I always get the message :

MMSYSTEM281 This file could not be played.  Check the filename or install a driver that supports this type of file.

But when I look at the multimedia devices, I see that a CD driver is installed, and that it is enabled.  So why do I get this message ?  And what should I do to be able to play CDs with my Delphi program ?

Thanks,

Lecossois.

Avatar of Epsylon
Epsylon

Hi Lecossois, I think you forgot to set the DeviceType property of TMediaPlayer to dtCDAudio:


  with MediaPlayer1 do
  begin
    FileName := 'H:';
    DeviceType := dtCDAudio;
    Open;
    Play;
  end;



Now it should work.

Regards,

Epsylon.

Avatar of lecossois

ASKER

Sorry Epsylon,

I did set the DeviceType value.  As a matter of fact, it doesn't even matter if I select dtCDAudio or dtAutoSelect.  The result is just the same.

I must be something else...

Lecossois.

Have you set the filename property too?

Btw: what delphi version are you using?
And make sure you have no other CD players open.....
set the autoopen property to false in object inspector
Could be....

Lecossois, put a >>NEW<< MediaPlayer component on your form and set the the filename and DeviceType properties as descibed above and set AutoOpen to true >>OR<< use the code.

Epsylon.
hi,
there is a bug in Delphi4 mplayer.pas unit.
Do the following:
1. open mplayer.pas from your Delphi's SOURCE\VCL directory
2. find TMediaPlayer.Open procedure
3. look for following code:

  if FDeviceType <> dtAutoSelect then {fill in Device Type}
   OpenParm.lpstrDeviceType := DeviceName[FDeviceType];
  OpenParm.lpstrElementName := PChar(FElementName);

4. insert one line so your code look like

  if FDeviceType <> dtAutoSelect then {fill in Device Type}
   OpenParm.lpstrDeviceType := DeviceName[FDeviceType];
  if FElementName <> '' then {<<<< INSERT THIS LINE}
   OpenParm.lpstrElementName := PChar(FElementName);

5. Save and compile this unit
6. Copy compiled unit mplayer.dcu to Delphi's SLIB directory (overwrite existing mpayer.dcu)

Enjoy!

A.
First of all, I had some trouble compiling this unit (since it is not part of a project).  I used the command line compiler, and got some messages like 'Could not find mplayer.res'.  But it compiled.

Nothing has changed actually.

But now I saw that the message changes when I change the device type.  I see the CD indication light flashing up very shortly, and I get the message :

MMSYSTEM296 : The file cannot be played on the specified MCI device.  The file may be corrupt, or not in the correct format.

When I select dtAutoSelect I get the old message.  With dtCDAudio I get the new message.

Some of the properties :
AutoEnable := False;
AutoOpen := False;
DeviceType := dtCDAudio;
Filename is blank

I tried to play a .WAV file, but that didn't work either.  No error messages, but I didn't hear anything.
Strangely enough, I could play an .AVI file.

Lecossois.

set FileName='D:' , where D: is your CD drive.

A.
btw, lecossois, are you using Delphi 4.0 or higher?

A.
It's working now !!!!!!!!  I changed the filename in I: (my CD drive) and it works.  How come this is not documented ??

333, just propose an answer and you'll get the points.

BTW, I'm using Delphi 4 (build 5.104) Update pack 2.

Thanks,

Lecossois.



ASKER CERTIFIED SOLUTION
Avatar of 333
333

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Lecossois, I wrote about the Filename property in my first answer and again in one of my comments. So I think I have earned the points. Don't you?

Epsylon.
Barry, please tell me, what do you think about this.....
Oops, indeed.  Well, let me solve it this way : I'll ask a question to Epsylon with the same amount of points.  This way you'll get the points.

333 can keep his points for proposing the patch.

This way everybody is (hopefully) happy.

Lecossois.



Thanks Lecossois, now I am happy again   :o)

Why this feature is not documented, I don't know. I figured it out myself. Because I have 2 CDROM drives the only way to select which drive to use is the Filename property.

Cheers,

Epsylon.
this was documented, but you should find this documentation yourself. :)
i found this somwhere in Borland's website (in White Papers section i think).

A.