Delphi: EMCIDeviceError when starting MCI
Asked Answered
S

2

7

I use the TMediaPlayer component for playing music.

It works fine with most of my tracks. But it doesn't work with some tracks. When I want to play them, the following error message is shown:

alt text

Which is German but roughly means that:

In the project pMusicPlayer.exe an exception of the class EMCIDeviceError occurred. Message: "Error when starting MCI.". Process was stopped. Continue with "Single Command/Statement" or "Start".

The program quits directly after calling the procedure "Play" of TMediaPlayer.

This error occurred with the following file for example:

  • file size: 7.40 MB
  • duration: 4:02 minutes
  • bitrate: 256 kBit/s

I've encoded this file with a bitrate of 128 kBit/s and thus a file size of 3.70 MB: It works fine!

What's wrong with the first file? Windows Media Player or other programs can play it without any problems.

Is it possible that Delphi's TMediaPlayer cannot handle big files (e.g. > 5 MB) or files with a high bitrate (e.g. > 128 kBit/s)?

What can I do to solve the problem?

Additional question: Why can't I use try/except to prevent the message window?

  try
    Player.Play;
  except
    showmessage('Cannot be played');
  end;

This doesn't work.

Selfsacrifice answered 14/3, 2010 at 19:55 Comment(6)
Turn on the "debug DCUs" linker option and step through the Play method to find the API error code that triggered Delphi to raise that exception.Tridimensional
I've turned on the "debug DCUs" but I don't know how to step through the "Play" method!? I've opened the MMSystem.pas additionally. But how do I step through it? There's no error while compiling but at runtime.Selfsacrifice
What are you using to encode your mp3s?Cowskin
I wonder what will happen tomorrow. OP has 91 rep and question has 200 rep bounty.Analgesic
AFAIK the points are removed when he start the bounty, not after. Points are also removed even if no answer is accepted.Forney
A big album image makes the problem. In my case 441kb image does.Cerumen
F
2

OK I found out the source of the problem. I used this small Delphi MP3 Player Tutorial (you can download project there) to test your MP3 file and I got the same error as you have with your MP3.

After some tests I found out that others MP3 files play well with that tutorial application. Your MP3 worked well with Windows Media Player and other multimedia players.

Yes re-encoding the file solve the problem, but it's not the true problem. The problem come from the metadata of the MP3 (the ID3 tags) and not the sound encoding itself.

I used Mp3tag to only remove the tags on the file and everything played well after that, no EMCIDeviceError.

It seems that TMediaPlayer can crash with some format of metadata. I also saw TMediaPlayer bug reports with MP3 files that embeded JPEG cover art too during my search.

Most people that were answering people bugs about TMediaPlayer on forums I looked were saying that TMediaPlayer is really outdated and is generally bad (I think it haven't been updated in like 10 years). If you want strong MP3 support in your application consider using another component. You could also use the Windows Media Player ActiveX in your Delphi application too.

For your additional question about the try/except try something like:

try
    //load & play here
except
    on E:Exception do
        ShowMessage('Cannot be played! ' + E.Message);
end;

Or consider using a TApplicationEvents if it's not catching the error.

Forney answered 16/3, 2010 at 20:14 Comment(2)
Thank you! Your code doesn't work. The message window (as shown above) still appears. My current WMP version is 11 but it didn't work with version 9, either. Problematic MP3: rapidshare.com/files/364267687/…Selfsacrifice
The try should catch the exception and pop the "Cannot be played!" message... Is it catched?Forney
C
1

Have you tried putting at TApplicationEvents control on your form, and handling the OnException Event.

procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
  E: Exception);
begin
  if E is EMCIDeviceError  then
    begin
     MessageDlg('Cannot be played, '+ e.message, mtError, [mbOK], 0)
     //Or Do Nothing...
    end else
     MessageDlg(e.message, mtError, [mbOK], 0);
end;

The Exception is raised on the Open, not the Play. So if you can change your code to trap exceptions on the open procedure.

  MediaPlayer2.filename :='';
  try
    MediaPlayer2.Open;
  except
   on E: Exception do
    MessageDlg('Can not be opened, '+ E.message, mtError, [mbOK], 0);
  end;
  if MediaPlayer2.Error = 0 then
    MediaPlayer2.play;

i re-encoded the mp3 using winlame and it works. What are you using to encode your mp3s?

Cowskin answered 16/3, 2010 at 23:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.