grimmdude / MidiPlayerJS

♬ MIDI parser & player engine for browser or Node. As a parser converts MIDI events into JSON. Works well with single or multitrack MIDI files.
https://grimmdude.com/MidiPlayerJS/
MIT License
359 stars 52 forks source link

Using in browser, require is not finding midi-player-js #23

Closed fornof closed 6 years ago

fornof commented 6 years ago
<script src="node_modules/midi-player-js/browser/midiplayer.js" type="text/javascript"></script>
Error: Uncaught (in promise) Error: Cannot find module 'midi-player-js'

when trying default script:
var MidiPlayer = require('midi-player-js');

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

// Load a MIDI file
Player.loadFile(url);
Player.play(); 

It is probably something simple I'm doing wrong.

grimmdude commented 6 years ago

Hi @fornof,

Thanks for the message. When using the built browser file in this library you should be able to access the global MidiPlayer class without using require().

var MidiPlayer = MidiPlayer;

Let me know if you have any issues with that.

-Garrett

grimmdude commented 6 years ago

You may also run into obstacles when using Player.loadFile() in the browser. Check out the source on the demo for a working example http://grimmdude.com/MidiPlayerJS/demo/js/app.js

-Garrett

fornof commented 6 years ago

I used the example and have it showing note on and note off in the console. However no notes are playing because the Soundfont /instrument is not found. Its another issue, I'll read the documentation some more and open up another issue if I cannot figure it out. Thank you so much for your help!

grimmdude commented 6 years ago

Yea, this library provides the player engine but no mechanism to play sounds. So, you can same sound font library this demo uses (https://github.com/danigb/soundfont-player) or any other one you wish.

Let me know if you need any help.

-Garrett

grimmdude commented 6 years ago

@fornof, noticed you re-opened this issue. Are you still have trouble?

-Garrett

fornof commented 6 years ago

I was going to reply, then followed your link to get notes to turn off when even off was pressed. https://github.com/danigb/soundfont-player/issues/59 It works, I just never closed/finished replying to this issue. thanks for following up!