MidiAudioPlayer

MidiAudioPlayer

A lightweight JavaScript MIDI audio player built on top of the Web Audio API using WebAudioFont. This package enables playback of MIDI files directly in the browser with minimal setup and no heavy dependencies.

Features

Installation

npm install midi-audio-player

Usage

Basic Example


				import MidiAudioPlayer from 'midi-audio-player';

				const response = await fetch('/examples/data/iwillsurvive.mid');
				const buffer = await response.arrayBuffer();

				const player = new MidiAudioPlayer({
				  preset: presetData,
				  volume: 0.6,
				  onEndFile: async () => await this.playNextSong()
				});

				player.play(buffer);
			

Control Playback


				player.play();
				player.pause();
				player.stop();
			

Working with AudioContext

Due to browser autoplay restrictions, you should ensure that your AudioContext is resumed after a user interaction.

CLI

This package provides a CLI tool for downloading and converting WebAudioFont assets. You need to provide a WebAudioFont ID and the json file for the destination.

webaudiofont "0000_Chaos_sf2_file" "dest/preset.json"

You can find presets here: Srgy Surkv's WebAudioFonts

Browser Compatibility

Requires a modern browser with support for:

License

MIT LICENSE

Author

Maxime Larrivée-Roy

Repository

https://github.com/ZmotriN/midi-audio-player


Examples

Basic example


Documentation