Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can't play audio CDs with TMediaPlayer

Posted on 1999-07-02
17
Medium Priority
?
590 Views
Last Modified: 2010-04-06
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.

0
Comment
Question by:lecossois
[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
  • 7
  • 5
  • 4
  • +1
17 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385910
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.

0
 

Author Comment

by:lecossois
ID: 1385911
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.

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385912
Have you set the filename property too?

Btw: what delphi version are you using?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:Epsylon
ID: 1385913
And make sure you have no other CD players open.....
0
 
LVL 17

Expert Comment

by:inthe
ID: 1385914
set the autoopen property to false in object inspector
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385915
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.
0
 
LVL 2

Expert Comment

by:333
ID: 1385916
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.
0
 

Author Comment

by:lecossois
ID: 1385917
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.

0
 
LVL 2

Expert Comment

by:333
ID: 1385918
set FileName='D:' , where D: is your CD drive.

A.
0
 
LVL 2

Expert Comment

by:333
ID: 1385919
btw, lecossois, are you using Delphi 4.0 or higher?

A.
0
 

Author Comment

by:lecossois
ID: 1385920
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.



0
 
LVL 2

Accepted Solution

by:
333 earned 200 total points
ID: 1385921
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.

P.S. This workaround works on Delphi 4.0, but it doesn't work with 4.2, because
OpenParam.lpstrElementName doesn't initialize as empty string as it was in D4.0 and if FElementName is empty, assignment OpenParm.lpstrElementName := PChar(FElementName); does nothing (OpenParm.lpstrElementName is still not empty). So workaround for D4.2 is set FileName property to CD drive letter (this works also with D4).
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385922
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.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385923
Barry, please tell me, what do you think about this.....
0
 

Author Comment

by:lecossois
ID: 1385924
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.



0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385925
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.
0
 
LVL 2

Expert Comment

by:333
ID: 1385926
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

688 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