Monthly Archives : June 2010

Embed flash MP3 player on website with Javascript

Post on June 13th,2010 by Posted in programming languages| Tagged in , , | 3 Comments

This article will show you how to use the Javascript SWFObject to embed a flash MP3 player on your website. Basically the code is the same as the previous flash video code. Before you include the Javascript part, you will need to create this div element within your html body tag first,

<div id=”your_mp3_player”>If you can see this text, then your computer will not be able to play this flash MP3, please install the player…</div>

If the user computer does not has flash player installed or does not has the right version of flash player installed, then he will only see the above text.

Now within the head tag of your html file, enter this Javascript code, you will need to include the swfobject.js file first in order to use the SWFObject and its method,

<script type=”text/javascript” src=”swfobject.js”></script>

then with this super simple code, you will be able to embed flash MP3 on your site.

<script type=”text/javascript”>
swfobject.embedSWF(“yourmp3file.swf”,”your_mp3_player”,”350″,”100″,”8.0.0″);
</script>

and that is it, when you load your web page and if your computer has flash player with the minimum version of 8.0.0, then you will see a flash MP3 player (350 x 100) appears on that page, the above script will look for the div tag with id=your_mp3_player and replaced the text with the new flash MP3 player.