Determining When a Midi Audio Player Has Finished Playing - Java Media

Java examples for Media:Audio

Description

Determining When a Midi Audio Player Has Finished Playing

Demo Code

import javax.sound.midi.MetaEventListener;
import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequencer;

public class Main {

  public void main(String[] argv) {
    try {//from   w w  w .  j  a  v  a 2  s .  c om
      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.open();
      sequencer.addMetaEventListener(new MetaEventListener() {
        public void meta(MetaMessage event) {
          if (event.getType() == 47) {
            // Sequencer is done playing
          }
        }
      });

    } catch (MidiUnavailableException e) {
    }
  }
}

Related Tutorials