# midi-player-js

> Midi parser & player engine for browser or Node. Works well with single or multitrack MIDI files.

Latest version **2.0.17** (published 2026-03-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install midi-player-js
pnpm add midi-player-js
yarn add midi-player-js
bun add midi-player-js
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.17 |
| Published | 2026-03-01 |
| First published | 2016-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10.0.0 |
| Dependencies | 0 |
| Unpacked size | 187.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 397 |
| Author | Garrett Grimm |
| Maintainers | grimmdude |
| Keywords | midi, midi-file, midi-parser, midi-player, parser, player, music, audio, smf |

## Links

- npm: https://www.npmjs.com/package/midi-player-js
- Repository: https://github.com/grimmdude/MidiPlayerJS
- Homepage: https://github.com/grimmdude/MidiPlayerJS#readme
- Issues: https://github.com/grimmdude/MidiPlayerJS/issues
- npm.io page: https://npm.io/package/midi-player-js

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.0.17 (latest) — 2026-03-01
- 2.0.16 — 2021-09-13
- 2.0.15 — 2021-09-13
- 2.0.14 — 2021-04-08
- 2.0.13 — 2020-05-25
- 2.0.12 — 2020-05-25
- 2.0.11 — 2020-05-24
- 2.0.10 — 2020-05-22
- 2.0.9 — 2020-05-18
- 2.0.8 — 2020-05-16
- 2.0.7 — 2020-05-11
- 2.0.6 — 2020-05-11
- 2.0.5 — 2018-11-21
- 2.0.4 — 2018-08-13
- 2.0.3 — 2018-03-15
- … 13 more at https://npm.io/package/midi-player-js/versions

## README

# &#9836; MidiPlayerJS
[![npm version](https://badge.fury.io/js/midi-player-js.svg)](https://badge.fury.io/js/midi-player-js)
[![CI](https://github.com/grimmdude/MidiPlayerJS/actions/workflows/node.js.yml/badge.svg)](https://github.com/grimmdude/MidiPlayerJS/actions/workflows/node.js.yml)

MidiPlayerJS is a JavaScript library which reads standard MIDI files and emits JSON events in real time.  This player does not generate any audio, but by attaching a handler to the event emitter you can trigger any code you like which could play audio, control visualizations, feed into a MIDI interface, etc.

## Demos
* [Neopixel Music](https://github.com/robertvorthman/neopixel-music) by robertvorthman @robertvorthman
* [Autocomposer](https://github.com/rjsalvadorr/autocomposer-js) by RJ Salvador @rjsalvadorr
* [Simple Browser Player](http://grimmdude.com/MidiPlayerJS/) by Garrett Grimm @grimmdude
* [Orchestra](https://lexcast.github.io/orchestra/) by Daniel Alejandro Cast @lexcast

## Getting Started
Using MidiPlayerJS is pretty simple.  Create a new player by instantiating `MidiPlayer.Player` with an event handler to be called for every MIDI event.  Then you can load and play a MIDI file.

```js
import MidiPlayer from 'midi-player-js';

// Initialize player and register event handler
const Player = new MidiPlayer.Player(function(event) {
	console.log(event);
});

// Load a MIDI file
Player.loadFile('./test.mid');
Player.play();
```
## Player Events
There are a handful of events on the `Player` object which you can subscribe to using the `Player.on()` method.  Some events pass data as the first argument of the callback as described below:

```js
Player.on('fileLoaded', function() {
    // Do something when file is loaded
});

Player.on('playing', function(currentTick) {
    // Do something while player is playing
    // (this is repeatedly triggered within the play loop)
});

Player.on('midiEvent', function(event) {
    // Do something when a MIDI event is fired.
    // (this is the same as passing a function to MidiPlayer.Player() when instantiating.
});

Player.on('endOfFile', function() {
    // Do something when end of the file has been reached.
});
```

Note that because of a common practice called "running status" many MIDI files may use `Note on` events with `0` velocity in place of `Note off` events.

## See Also

Need to generate MIDI files programmatically? Check out [MidiWriterJS](https://github.com/grimmdude/MidiWriterJS) — a JavaScript library for creating expressive multi-track MIDI files. Together they form a complete MIDI toolkit:

- **MidiPlayerJS** — parse and play MIDI files with real-time event callbacks
- **MidiWriterJS** — generate MIDI files programmatically

## Full API Documentation
[http://grimmdude.com/MidiPlayerJS/docs/](http://grimmdude.com/MidiPlayerJS/docs/)

---
_Source: https://npm.io/package/midi-player-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
