Click to See Complete Forum and Search --> : Standards-compliant background music


AdamGundry
04-21-2003, 06:18 AM
Hi everyone

I'm designing a few pages in HTML 4.01 Transitional and I have to include background music on one. (a MID file). If at all possible, I want to make the code fully standards-compliant, but I can't find how to include music correctly.

I've tried <bgsound> and <embed>, both of which work but do not validate as correct HTML.

Does anyone know how I can include music that meets the HTML 4.01 standards?

Adam

P.S. I don't actually think music should be included in pages, as a general rule, but the syllabus says it must be included. :mad:

jeffmott
04-21-2003, 06:38 AM
The way it is technically supposed to be done is with object (http://www.w3.org/TR/html401/struct/objects.html#edef-OBJECT). However, support for this element is scratchy where it is supported at all. This is a case where you will have to use proprietary elements for it to work in as many browsers as possible.

Allan Saw
04-21-2003, 06:40 AM
Here is a javascript snippet that will play a background sound and be compatible with a number of browsers.

<SCRIPT LANGUAGE="JavaScript">
<!--
var MSIE=navigator.userAgent.indexOf("MSIE");
var NETS=navigator.userAgent.indexOf("Netscape");
var OPER=navigator.userAgent.indexOf("Opera");
if((MSIE>-1) || (OPER>-1)) {
document.write("<BGSOUND SRC=mysong.mid LOOP=INFINITE>");
} else {
document.write("<EMBED SRC=mysong.mid AUTOSTART=TRUE ");
document.write("HIDDEN=true VOLUME=100 LOOP=TRUE>");
}
//-->
</SCRIPT>

AdamGundry
04-21-2003, 06:43 AM
Thanks, jeffmott. I thought it might be object, but I couldn't figure out how to do it properly. I'll just have to use embed/bgsound, then point out in my evaluation it is invalid code.

Oh, the joys of school ICT coursework. :rolleyes:

Adam