简体   繁体   中英

Midi/Binary File Decoding in Javascript

I have some midi files that I am returning to the client using Axios, whenever I try and parse them using tone.js I get some encoding issues:

Uncaught (in promise) Bad MIDI file.  Expected 'MTrk', got: '¿½MT'

I have tried using a FileReader, copying to a typed array as per this post but whatever I do I get the same error.

Here is the method in question:

static convertMidiToJson(midi: Blob) {
let result = new Midi();

midi.arrayBuffer().then((it) => {
  result = new Midi(it);
});

return result;

}

midi is just the result.Data from the Axios call.

Any help greatly appreciated!

I had missed the responseType: blob in the axios call. Once I added that, it parsed correctly:

return axios
      .get(it.data, {
        responseType: "blob",
      })
      .then((itr) => {
        return new Blob([itr.data], { type: "audio/midi" });
      });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM