my code plays a midi java sound file , but i want to play it in a loop constantly ! can somebody help me please !

import javax.sound.midi.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class MidiPlayer{

  public static void main(String[] args) {
      try {
          Sequencer sequencer = MidiSystem.getSequencer();
          if (sequencer == null)
              throw new MidiUnavailableException();
          sequencer.open();
          FileInputStream is = new FileInputStream("smb2.mid");
          Sequence Seq = MidiSystem.getSequence(is);
          sequencer.setSequence(Seq);
          sequencer.start();

      } catch (Exception e) {
          e.printStackTrace();
      }
  }
}

Edited 6 Years Ago by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

Hey sorry I'm not here to answer your question but to ask one. When you run this code does it play the midi and the code stops running or does it it keep running after it plays the sound. The reason I'm asking is because whenever I run code similar to that it just keeps running after it plays the midi.

Hey sorry I'm not here to answer your question but to ask one. When you run this code does it play the midi and the code stops running or does it it keep running after it plays the sound. The reason I'm asking is because whenever I run code similar to that it just keeps running after it plays the midi.

Well the song palys completly then stops...i want it to keep playing on !

Why not use a for loop:

for (boolean toBreak; toBreak == false; sequencer.start()) {
//check if the user want's to exit, wait a certain amount of milliseconds, whatever.
}

This article has been dead for over six months. Start a new discussion instead.