This looks like it might work but I don't have a clue how I would call, compile or whatnot on my server to get an executable program.
How to determine the duration of a Midi audio file
This Java tip illustrates a method of determining the duration of a Midi audio file. Developer may use this in gaming applications where there is a need for playing different audios. Further this may also be used in your own media player. Here in this tip a sequencer fires a meta message event when a midi file has finished playing.
// From file
Sequence sequence = MidiSystem.getSequence(new File("midiaudiofile"));
// From URL
sequence = MidiSystem.getSequence(new URL("http://hostname/midiaudiofile"));
// Create a sequencer for the sequence
Sequencer sequencer = MidiSystem.getSequencer();
double durationInSecs = sequencer.getMicrosecondLength() / 1000000.0;