0

I'm trying to use MIDI.js (because I don't know how else to play MIDI files smoothly when the browser tab is not in focus). More specifically, I'm trying a new version of MIDI.js called midicube.

Like in the readme, I do

<script src="releases/midicube.js"></script>
<script>
MIDI.loadPlugin({
    // this only has piano. 
    // for other sounds install the MIDI.js 
    // soundfonts somewhere.
    soundfontUrl: "./examples/soundfont/",
    onerror: console.warn,
    onsuccess: () => {
        MIDI.noteOn(0, 60, 0);
    }
});
</script>

but I get

audioDetect.js:38 Uncaught TypeError: Cannot read properties of null (reading 'appendChild')
    at s (audioDetect.js:38:22)
    at audioDetect.js:106:9
    at Module.$t (index.js:94:5)
    at mytest.html:3:6
s @ audioDetect.js:38
(anonymous) @ audioDetect.js:106
$t @ index.js:94
(anonymous) @ mytest.html:3
audioDetect.js:36 Uncaught TypeError: Cannot read properties of null (reading 'removeChild')
    at Audio.<anonymous> (audioDetect.js:36:8)

Here are the lines of code that cause the error. Am I doing something wrong or is midicube outdated in some way (latest commit 3 years ago)?

root
  • 1,812
  • 1
  • 12
  • 26
  • 1
    Perhaps you need to wait for the DOM to be ready before that code starts. – Pointy Dec 26 '22 at 17:09
  • @Pointy Thanks, I wrapped the call to `loadPlugin` inside `setTimeout(() => { ` ... `}, 5000);` and now I'm getting different errors. – root Dec 26 '22 at 17:15
  • You can also handle a "DOMContentLoaded" event instead of using a timer. Usually simply moving your ` – Pointy Dec 26 '22 at 17:17

0 Answers0