nfroidure / midiplayer

Play MIDI file right in your browser with the WebMIDIAPI

Home Page:https://karaoke.insertafter.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MIDIPlayer

MIDIPlayer allows you to play MIDI files in your browser with the help of the WebMIDIAPI.

NPM version Dependency Status devDependency Status

MIDIPlayer can be used either in modern browsers (pick the last bundle) or with NodeJS by installing the following NPM module :

npm install midiplayer

This player is used for this MIDI Karaoke Player

## Usage

//Require MIDIPlayer and MIDIFile modules
var MIDIPlayer = require('midiplayer');
var MIDIFile = require('midifile');


navigator.requestMIDIAccess().then(function(midiAccess) {
	// Creating player
	var midiPlayer = new MIDIPlayer({
	  'output': midiAccess.outputs()[0]
	});

	// creating the MidiFile instance from a buffer (view MIDIFile README)
	var midiFile = new MIDIFile(buffer);

	// Loading the midiFile instance in the player
	midiPlayer.load(midiFile);

	// Playing
	midiPlayer.play(function() {
		console.log('Play ended');
	});

	// Volume
	midiPlayer.volume = 80; // in percent

	// Pausing
	midiPlayer.pause();

	// Resuming
	midiPlayer.resume();

	// Stopping
	midiPlayer.stop();

	// Playing again and loop
	midiPlayer.play(function playCallback() {
		midiPlayer.play(playCallback);
	});

}, function() {
	console.log('No midi output');
});

License

Copyright Nicolas Froidure 2013. MIT licence.

About

Play MIDI file right in your browser with the WebMIDIAPI

https://karaoke.insertafter.com/

License:MIT License


Languages

Language:JavaScript 58.0%Language:HTML 42.0%