Open sonicviz opened 5 years ago
I have the same problem with this lib and investigated a bit. I found that the expected string "MTrk" is off by a few bytes. The midi files and sound banks etc. are loaded in Unity as TextAsset and by using TextAsset.bytes. In the documentation it says:
If you're using the text asset to contain binary data, you should make sure the file has the .bytes extension. For any other of the extentions the TextImporter will try to strip nonascii characters if it is unable to parse the file as an utf8 string.
Thus, I guess that Unity is stripping some bytes of the asset, which leads to a broken file. It works after renaming every ".txt" file in the Resources folder of this repo to ".bytes" (e.g. "GROOVE.mid.bytes" instead "GROOVE.mid.txt").
Fyi the error it’s throwing is in MidiFile.cs on loading the default scene with midis/groove.mid line 237 (which is not apparent in the Unity console message as it from a level higher:
Error Loading Midi: Midi Failed to Load! UnityEngine.Debug:Log(Object) CSharpSynth.Sequencer.MidiSequencer:LoadMidi(String, Boolean) (at Assets/ThirdParty/CSharpSynth/Sequencer/MidiSequencer.cs:153) MIDIPlayer:LoadSong(String) (at Assets/Scripts/MIDIPlayer.cs:51) MIDIPlayer:Update() (at Assets/Scripts/MIDIPlayer.cs:70)