Delphi: EMCIDeviceError when starting MCI

I am using the TMediaPlayer component to play music.

It works great with most of my tracks. But this does not work with some tracks. When I want to play them, the following error message is displayed:

alt text

It is German, but roughly means that:

An exception to the EMCIDeviceError class occurred in the pMusicPlayer.exe project. Message: "Error starting MCI.". The process has been stopped. Continue with “Single Command / Instruction” or “Start”.

The program exits immediately after calling the "Play" procedure from TMediaPlayer.

This error occurred with the following file, for example:

  • file size: 7.40 MB
  • duration: 4:02 minutes
  • bit rate: 256 kbps

I encoded this file with a bit rate of 128 kbps and thus with a file size of 3.70 MB: it works great!

What is wrong with the first file? Windows Media Player or other programs can play it seamlessly.

Is it possible that Delphi TMediaPlayer cannot process large files (e.g.> 5 MB) or files with high data transfer rates (e.g.> 128 kbps)?

What can I do to solve the problem?

Additional question: why can't I use try / in addition to prevent the message box?

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

This does not work

+4
source share
2 answers

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

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

Yes, re-encoding the file solves the problem, but this is not a real problem. The problem arises from the MP3 metadata (ID3 tags), and not from the audio encoding itself.

I used Mp3tag only to remove tags in the file, and after that everything worked out well, no EMCIDeviceError.

It seems that TMediaPlayer may break with some metadata format. I also saw TMediaPlayer error messages with MP3 files that were also included in the JPEG cover during my search.

Most of the people who answered people’s errors about TMediaPlayer in the forums I watched said that TMediaPlayer is really outdated and usually bad (I think it has not been updated in about 10 years). If you need powerful MP3 support in your application, consider another component . You can also use Windows Media Player ActiveX in your Delphi application.

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

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

Or consider using TApplicationEvents if it does not catch the error.

+2
source

Have you tried applying the TApplicationEvents function in 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; 

An exception occurs in Open, not in Play. Therefore, if you can change your code to exclude exceptions in an 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 transcoded mp3 using winlame and it works. What do you use to encode your mp3s?

+1
source

Source: https://habr.com/ru/post/1304088/


All Articles