I work in Android studio and I want to save midi files to the internal memory of the device, but when I try to do this, the data is recorded incorrectly and the classic player cannot open it, but the file opens well in musescore
here is my code for writing a midi file to a regular file
public void writeToFile(File outFile) throws IOException
{
FileOutputStream fout = new FileOutputStream(outFile);
fout.write(IDENTIFIER);
fout.write(MidiUtil.intToBytes(6, 4));
fout.write(MidiUtil.intToBytes(mType, 2));
fout.write(MidiUtil.intToBytes(mTrackCount, 2));
fout.write(MidiUtil.intToBytes(mResolution, 2));
for(MidiTrack T : mTracks)
{
T.writeToFile(fout);
}
fout.flush();
fout.close();
}
everything works in IntelliJ IDEA, but not in Android studio. This happens even when I try to just write the file unchanged
try {
midiFile = new MidiFile(file);
midiFile.writeToFile(file);
} catch (IOException e) {
Log.d("midifile", "open failed");
}