public void play() {
    this.thread = new Thread() {
      public void run() {
        if (isMidi) {
          sequencer.start();
          int timer = 5;
          while (sequencer != null && sequencer.isRunning() && timer >= 0) {
            try {
              Thread.sleep(500);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
            timer--;
          }
        } else {
          clip.start();
          int timer = 5;
          while (clip != null && clip.isActive() && timer >= 0) {
            try {
              Thread.sleep(500);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
            timer--;
          }
        }
        reset();
      }
    };
    thread.start();
  }