·: Site description :·
Welcome!

NetBulge.com provides code, scripts, tips & tricks and general information about web development aimed to help webmasters and web designers.

Instead of packing all the info we can get into a huge database, our goal is to produce a high quality compilation of code snippets and articles. Web developers will find in these pages a fresh and savvy view of most of the issues concerning programming and designing for the web; as well as a good site to visit regularly for help and inspiration.

Enjoy!
Zones
Navigation
Search

Sessions

NetBulge.com RSS2 feed



About Hosting:

I use and recommend Hostgator for all my hosting needs. It is the only company I have tried (and I have tried plenty) that hasn't given me a headache and responds quickly and fairly to everything I ever need. I run 3 accounts that host over 20 sites with Hostgator and I am happy recommending it to all my family, friends and clients. If you are looking for a cheap yet solid host, IMO Hostgator is the way to go. I do get a comission if you register through the link, but even if you don't like me and don't want me to get a comission, go to Hostgator for your hosting needs and save yourself plenty of cash and headaches.


 Print version Send article via e-mail  

HTML Music Code


web zone resourcesInserting an audio file into a web document should be a somewhat uneventful task. Actually, if you do not care about standards it is rather simple since the non-standard <embed> tag works very well in 95% of browsers. It only gets complicated when trying to follow the W3C specification. In this article I provide both methods and you can decide for yourself.


Inserting an mp3 file using the embed tag is as easy as everything should be:

<embed src="music.mp3" width="200" height="20" autostart="true" loop="true">

The funny thing is the embed tag, although widely supported by most browsers and overall the safest bet for inserting music in a page, has never been part of the standard definition of HTML. In any event, if you, dear visitor, do not care about these so called HTML standards and are only looking for a simple and effective way to insert an mp3 file in your web page, then look no further; use the above code with the embed tag and disregard the rest of this monologue.

Now, back to my rambling, the standard method for inserting multimedia into a webpage is the object tag. The problem is that, although it was originally a Microsoft tag, Internet Explorer disregards the recommended use. The following html code works correctly in Firefox:

<object data="music.mp3" type="audio/x-mpeg">
</object>

Yet IE ignores this simple and clear request.

Microsoft likes its multimedia objects like it likes its coffee, bizarre and unapologetic. So, in order to make the audio file play in IE we must first declare the control that will handle it; the first choice being the dear old Windows Media Player, a bulky tool that a friend of mine affectionately calls the "Memory Eating Monster". But to follow this requirement correctly we must use the lengthy and highly proprietary ActiveX ID system that of course is only recognized in Windows and will crash and burn on any other platform:

<OBJECT ID="MediaPlayer1" WIDTH=320 HEIGHT=240
CLASSID="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"
CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/
nsmp2inf.cab#Version=5,1,52,701"
standby="Loading Microsoft Windows Media Player components..."
type="application/x-oleobject">
<Param Name="FileName" Value="music.mp3">
</OBJECT>

Cute isn't it? So, we are trapped either:

  1. Neglecting one browser's method in favor of the other
  2. Using both methods on the same page and hoping for the best
  3. Hacking this up into making it behave our way

Quite frankly, with the ready availability of the embed tag for inserting music into a web page, I really don't feel like considering any of the <object> related alternatives. I don't normally insert audio in my HTML pages anyway, and I'm sure that if I ever have the need for it I'll be able to live with my page not validating or use a more extensible tool such as Flash.




Author : Esopo, Read 14281 times, Comments: 2
Rating :  rating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resources  |  Friday, 24. February 2006

Add new comment/Comments
Your rating :   Poor ranking resourcesrating resourcesrating resourcesrating resourcesrating resources Excellent




css stylescss stylesDid you know?
There is a wallpaper gallery? Yeap, it took me a while to code it and put it together for your entertainment. Check it out and, if you like it, drop me a line.
Visit gallery

Featured *
Many say this antivirus is much better than the leading AV in the market. The least I can say is that AVG performs extremely well and its price (free) is simply unbeatable. If you don’t have an antivirus right now or are not pleased with your current level of protection, you should give this one a try.

"The Mentors on the ERT site may answer a few direct questions, but the primary objective is to teach."
ERT is a free site that offers good quality information on several fields of technology, and their forums are like no other. This is the new wave of knowledge exchange. Don't miss this site!
http://www.expertsrt.com/