Is it possible to load a midi file using createjs?

95 views Asked by At

I am working on a createjs app that needs to load midi files as part of its function. I then plan to use midiplayer.js to play the file. However, I cannot find any examples of loading a midi file using createjs. It seems that I would want to load it as a binary and then feed it into midiplayer.js as an ArrayBuffer, which it can handle. I am stuck on how to read in a BINARY file type in createjs. Here is some example code as what I am trying to do:

let queue = new createjs.LoadQueue();
queue.on("complete", assets_loaded);
queue.on("fileload", handle_file_load);
queue.loadManifest([
{id: "bach_score", src: "Bach_score.png"},
{id: "football_stage", src:"Football.png"},
{id: '1badbar1s', src: "exampleplayer/e1/1badbar1.mid", type: createjs.Types.BINARY}]);

Everything seems to go fine. No errors are reported. I can load in the image files without any problem with a line like this:

let new_image = new createjs.Bitmap(queue.getResult("bach_score));

However, I cannot find an example of how to load in a binary file. Any help appreciated.

So here is an update. It appears I need to specify that this is of binary type. (I added that above). This should then call the binaryLoader class and give me back what I want. However, it doesn't seem to be working. Could this be a bug in createjs?

###Further update: 4/16/21

I dug through the createjs code and realized what is happening. Since the extension on my files is .mid (a midi file) soundjs is claiming processing of the file. One of the extensions listed is .mid as a SUPPORTED_EXTENSION on line 363 of sound.js. This checked to see if the browser supports midi files, and none do. I have to find a workaround for this.

1

There are 1 answers

0
Timothy Paustian On

I actually figured this out. It was a bug (in my opinion) in createjs. The soundjs module says it can handle a .mid file (midi) but then checks the browser and if the browser cannot handle it, it marks it as false. Thus, it makes a promise it cannot keep. I was able to fix it with just a few lines of code. It ends uploading the file as a raw binary and you have to deal with it from there. A more detailed description is available at the GitHub for SoundJS