How to Create an MP3 Player in PHP

by Fred Larrey
mp3 player image by patrimonio designs from

MP3 audio files can be easily embedded into your website using some simple PHP and HTML scripting. One way to create an MP3 player on your website would be to embed the MP3 file directly, however this can lead to problems on the client-side, because not everyone uses the same media browser plug-ins. To get around this problem, Google provides a freely available embed-able MP3 player. It automatically loads time information about the song you are playing and has a volume slider and time progress bar that allows you to skip within the song. Best of all, it works and looks the same on all computers.

Step 1

Open up your favorite text editor. Any text editor will do. This is where you will write your PHP script.

Step 2

Type the following PHP script into your text editor: \" GO Echo \"PHP Mp3 Player\" GO Print \"My MP3 Player:\" GO Echo \"\" GO ?>

Step 3

Select the \"MP3_FILE_URL\" text within the last Echo statement. Change it to the URL of your MP3 file on your server. For example, if your server was named \",\" the URL might look like: \"\".

Step 4

Go to \"File\" > \"Save As\" and type \"mp3player.php\" as the name of the file. Navigate to the root directory of your web server and click \"Save.\"

Open a web browser and type \"http://localhost/mp3player.php\" to open your MP3 player website. You will see the Google MP3 player, and you'll hear your MP3 file start to play. Remember, your web server will need to be running in order to use PHP. See the Tips section for more information on how to create a web server.


  • PHP is a web-based programming language, so in order to test or run PHP script you'll need access to a web server. If you are not running one, you can find some helpful information in the Resources section that will lead you in the right direction.


Photo Credits

  • mp3 player image by patrimonio designs from

About the Author

Fred Larrey hails from Providence, R.I., where he has been involved in computer science research since 2005. Some of his work has appeared in the annual "SIGGRAPH" graphics convention magazine. Larrey holds a bachelor's degree in computer science from Brown University.

More Articles