Delphi tmediaplayer don't play mp3 file with "strange" cover image embedded

894 views Asked by At

I have developed a mp3 player with Delphi (XE) using the BASS library.

Due to certain reasons, I want to remove the BASS libraries and want to use the TMediaPlayer component in Delphi (also want to "move" the project to Delphi 10 Seattle).

Now I found out that some of my mp3 files have a "strange" jpg image embedded.

Means, that the Delphi components run into an error due to the image.

With long time debugging I can say the following:

try
  mplMain.FileName := CurrentSong;

  progbSong.Max := mplMain.Duration;
  lblDuration.Text := DurationToString(mplMain.Duration);
  PlayClick(Self);

except
  on E: Exception do
  begin
    FMX.Dialogs.MessageDlg('Cannot play song: ' + CurrentSong + #10 + #13 +
                           'Reason: ' + E.Message,
                           TMsgDlgType.mtWarning, [TMsgDlgBtn.mbOK], 0,
      procedure(const AResult: TModalResult)
      begin
        MediaNext;
      end
    );
  end;
end;

This line:

mplMain.FileName := CurrentSong;

causes the problem.

Diving deeper in debugging it comes to here:

FMX.Media library:

procedure TMediaPlayer.SetFilename(const Value: String);
  ...
  FMedia := TMediaCodecManager.CreateFromFile(FFileName);
  ...

At the end it ends up in FMX.Media.Win:

constructor TWindowsMedia.Create(const AFileName: string);
  ...
  HR := FGraphBuilder.RenderFile(PChar(AFileName), nil);
  ...

When the line

HR := FGraphBuilder.RenderFile(PChar(AFileName), nil);

is called, in debug mode, the program just returns to the IDE.

In runtime mode, nothing happens. No error message, just "nothing".

As you can see, I wrapped the related line into a try...except block, but no error is raised. The program/player doesn't continue.

That's very bad for me, because I wanted to catch this "special case" and log the affected mp3 files to a logfile so that I can change the embedded image.

I found out that it is only caused by some images. Maybe they are "somehow corrupt", but shown in all other players.

When I remove the image and embed a "new" one and save the file, everything is fine and the TMediaPlayer can play the file.

How can I catch this certain kind of "error" to get the list of affected files?

1

There are 1 answers

0
XingFu ZhuanYun On

I got it managed now. Only in debug mode the application/player is exited without any thrown error and I find myself back in the IDE.

During runtime the try...except block works, when I chose an "affected file" manually. For the case that one file is played ("good one") and the next file is a "bad one", I had to change my "MediaNext" procedure. In this procedure I also had a try...except block when the filename was associated to the TMediaPlayer, but I just had set a bool variable for further use and didn't "jump" to the next file.

The code just was:

try
  mplMain.FileName := CurrentSong;

except
  on E:Exception do
    SongNotPlayable := true;

end;

Here I can implement a routine to log the affected mp3 files into a logfile and then jump to the next file (if exists). :-)

Thanks again to all!