简体   繁体   English

Javascript 中的 Midi/二进制文件解码

[英]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:我有一些使用 Axios 返回给客户端的 midi 文件,每当我尝试使用tone.js解析它们时,我都会遇到一些编码问题:

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.我曾尝试使用 FileReader,按照这篇文章复制到类型化数组,但无论我做什么,我都会遇到同样的错误。

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. midi 只是结果。来自 Axios 调用的数据。

Any help greatly appreciated!非常感谢任何帮助!

I had missed the responseType: blob in the axios call.我错过了 axios 调用中的 responseType: blob。 Once I added that, it parsed correctly:一旦我添加了它,它就会正确解析:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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