/** * Plays a MIDI Sequence * * @param sequence the Sequence to play * @throws JFugueException if there is a problem playing the music * @see MidiRenderer */ private void play(Sequence sequence) { // Open the sequencer openSequencer(); // Set the sequence try { getSequencer().setSequence(sequence); } catch (Exception e) { throw new JFugueException(JFugueException.ERROR_PLAYING_MUSIC + e.getMessage()); } setStarted(true); // Start the sequence getSequencer().start(); // Wait for the sequence to finish while (isPlaying() || isPaused()) { try { Thread.sleep(20); // don't hog all of the CPU } catch (InterruptedException e) { throw new JFugueException(JFugueException.ERROR_SLEEP); } } // Close the sequencer getSequencer().close(); setStarted(false); setFinished(true); }