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(); sequencer.open(); sequencer.setSequence(sequence); double durationInSecs = sequencer.getMicrosecondLength() / 1000000.0;