How to Embed a MIDI File into Your Web Page
What to Do
- View the source of this page.
- Copy from <SCRIPT> to </SCRIPT>
- Paste it into your web page.
- Change the "embed.mid" to the filename of your MIDI file.
- Change the "Bach's Invention #1" to the name of the tune or composition.
About this Script
- It will work for Internet Explorer's "BGSOUND".
- It will work for Netscape's or Explorer's "EMBED".
- It's JavaScript, so...
- It won't work if your visitors have disabled JavaScript.
- However, most people who dislike JavaScript pages probably also dislike embedded MIDI files, so this might be considered an advantage.
- It's "polite".
- It gives the name of the tune, so your visitor's know what they are listening to.
- It gives a link to the MIDI file, so visitors who like the tune can easily download the MIDI file.
- It shows the controls of the MIDI plugin, so visitors can stop (or replay) the MIDI file if they want to.
- "WIDTH=200 HEIGHT=80" should be large enough to work with any MIDI plugin. Some code you see on the Internet has this set too small. Be aware that sometimes what producers of MIDI plugins say, only works with their own plugin.
- The code is small and concise. It does everything necessary, but only what's necessary.
Advice
- Choose a MIDI file with a small file size, so it downloads quickly.
- Put the script at the bottom of the page, so your visitors can be reading the main part of the page while the MIDI file is loading.
- Read Many MIDI File Lovers Hate Embedded MIDI Files.
Perhaps you may decide not to embed a MIDI file on your page.
The Script
This is what the script looks like.
It might be better to list the source of this page rather than copy it from here.
<SCRIPT>
<!--
//Put the filename of the .mid file here.
k="embed.mid";
//Put the name of the tune here.
t="Bach's Invention #1";
// The rest doesn't need to be changed.
document.write('<P><CENTER><NOEMBED><BGSOUND SRC="'+k+'" AUTOSTART=TRUE LOOP=2></NOEMBED><EMBED SRC="'+k+'" WIDTH=200 HEIGHT=80 AUTOSTART=TRUE LOOP=2><P>')
document.write('<font size=2><a href="'+k+'">'+t+'</a></CENTER><P>')
// -->
</SCRIPT>