123Webmaster.com : Onsite : Building
Embedding Midi Files

by Ian McDonald
http://www.bigresources.com

This page is designed to explain how to embed a single midi file
and the various controls.

To embed a single file: auto start (start on page load ) It is hidden and repeats.

<!-- --><embed src="http://YOUR URL.mid" autostart="true" hidden="true" loop=true><!-- -->

To change this so that it does play automatically in page load:
changeautostart="true" to autostart="false".

To change this so that it only plays once:
change loop="true" to loop="false"

Allowing Users to Control the Music:
(using the control console)

Small Console:

<!-- --><embed src="http://YOUR URL.mid" height=16 width=47 autostart="true" controls="smallconsole" loop="true"><!-- -->
(gives users the play and stop buttons in a small console)

<!-- --><embed src="http://YOUR URL.mid" height=16 width=145 autostart="true" controls="smallconsole" loop="true"><!-- -->
(gives users the play, stop and volume control) 

Large Console:

<!-- --><embed src="http://YOUR URL.mid" controls="console" autostart="true" loop=true height=60 width=145><!-- -->


The "MASTERSOUND" Option:

The MASTERSOUND attribute lets you control a single sound track with multiple single control panels. IE: A seperate volume, pause, stop and play button.

1) First you have to give your midi file a name so your control button knows what to play, stop, etc.

<!-- --><embed src="http://YOUR URL.mid" autostart="true" loop="true" name="mymidi" ><!-- -->

2) Add name="mymidi" and MASTERSOUND to it like this below: ( "mymidi" is an example, it does not have to be called that)

<!-- --><embed src="http://YOUR URL.mid" autostart="true" loop="true" name="mymidi" MASTERSOUND><!-- -->

3) Add your control to it.
<!-- --><embed src="http://YOUR URL.mid" autostart="true" loop="true" name="mymidi" CONTROLS="playbutton" MASTERSOUND><!-- -->
 
  • volume: CONTROLS="volumelever"
  • stop:     CONTROLS="stopbutton"
  • Pause:  CONTROLS="pausebutton"
Is greyed out until you click it.
  • Play:     CONTROLS="playbutton"
Is greyed out until you click it.

A Text or Image Stop Button:

This will allow you to stop a playing midi with a text or image link.

Normally this would be used for sound that auto plays.

Insert this into the body of your page.
<script LANGUAGE="JavaScript">
function stop() { document.mymidi.stop()}
</script>
start the midi here.
stop
Stop The Music
In your link:
onClick="javascript:stop()"

Example: text
<!-- --><a href="javascript://" onClick="javascript:stop()">stop</a><!-- -->

Example: Image
<!-- --><a href="javascript://" onClick="javascript:stop()"><img src="stopthemusic.gif" border=0 height=60 width=60 alt="Stop The Music"></a><!-- -->


Discussion - Graphics & Multimedia
WebSites - Midi Related Scripts at A1JavaScripts.com