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

Usingin browser, TypeError: MidiPlayer is undefined #49

Closed Josema23 closed 5 years ago

Josema23 commented 5 years ago

I have seen another post where somebody asked about using the library in browser, so i added this to my code

<script type="text/javascript">

        var MidiPlayer = MidiPlayer

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

        // Load a MIDI file
        {% load static %}
        Player.loadFile('/media/{{cancion.midi}}');
        Player.play();
    </script>

It throws me this error:

TypeError: MidiPlayer is undefined

I'm a little bit lost on this, so I ask you if i have to load the script or something else to make it work correctly, because I just need to play a midi file

grimmdude commented 5 years ago

Hi @Josema23,

Looks like you figured this out? I see you're referencing MidiPlayer without defining so that's your issue.

-Garrett