Re: Delphi MP3 Player

Posted by webmaster Guido on February 08, 2007

In Reply to Delphi MP3 Player posted by Graham J Hadlington p12555 on February 06, 2007

: Has anyone created a mp3 player in Delphi? If so, is this for sale?

Don't buy one, roll your own MP3 player :)
It's very easy with Delphi's TMediaPlayer component, that allows you to add audio and/or video clips to your application. It opens a media device and plays, stops, pauses, etc., the specified audio and/or video file.

Here's the shortest example on how to play an MP3 file:

And there's your MP3 player in its most basic form, only 3 lines of code!

Over the next week, we're publishing a more detailed tutorial on programming your own MP3 player. To start with, we'll cover the possibilities of TMediaPlayer; next we'll add some whistles and bells like: selecting a file from a list, displaying the ID3 tag, displaying a progress bar, and so on...

The tutorial starts on this page: MP3 Player, part 1

A few programming tips, for those of you that are to impatient ;-)

  1. If you want the playback to start immediately after Button1 is clicked, just add a line of code:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      MediaPlayer1.Close;
      MediaPlayer1.FileName := 'c:\music\test.mp3';
      MediaPlayer1.Open; 
      MediaPlayer1.Play;
    end;
  2. For just playing MP3 files, your player doesn't need all those buttons. In the Object Inspector, you can change the property VisibleButtons and limit the buttons to just these three: btPlay, btPause and btStop.
     
  3. If the MP3 file that you want to play is located in the same directory as the exe-file of the program, as in applications that you want to distribute, change the code line for the FileName as follows:

    MediaPlayer1.FileName := ExtractFileDir(Application.ExeName) + '\test.mp3';

Guido, DelphiLand Team

Related articles

       

Follow Ups