By: X. Chen
Created on: 4/1/2015
Last Modified: 4/3/2015
Github site: https://github.com/chenx/MidiPlayer
MIDI is a widely used music format online. However the HTML5 Audio tag supports only wav/mp3/ogg formats so far. Playing MIDI usually uses the embed tag which requires the QuickTime plugin, or deprecated tag such as bgsound in IE, but not always work.
An alternative is to include all the files from which midi.js was made (Of course, the first way is much better):
You also need to include da.swf in the same directory as your html file. This is needed by Safari and Opera.
- Can specify these in constructor parameter list: midi, target, loop, maxLoop, end_callback.
- midi: MIDI file path.
- target: Target html element that this MIDI player is attached to.
- loop: Optinoal. Whether loop the play. Value is true/false, default is false.
- maxLoop: Optional. max number of loops to play when loop is true. Negative or 0 means infinite. Default is 1.
- end_callback: Optional. Callback function when MIDI ends. e.g., use this to reset target button value from "stop" back to "play".
- can specify a debug div, to display debug message: setDebugDiv(debug_div_id).
- Start/stop MIDI by: start(), stop().
- If a MIDI started play, call start() again will stop and then restart from beginning.
The disadvantage of  is that it does not have control over how a MIDI file is played: when clicking on the link more than once the file will be started multiple times and sounds chaotic; and there is no loop feature. Both are well handled by MidiPlayer.js here.
It can be a good idea to add MIDI support to HTML5 Audio tag, because MIDI files have much smaller size than wav/mp3, and the sound effects are very rich. Besides there is a large repertoire of MIDI music online.
IE support, like how  does.