private static void playMidi(String name, boolean loop, double volume) throws MidiUnavailableException, FileNotFoundException, IOException, InvalidMidiDataException { // Obtains the default Sequencer connected to a default device. Sequencer sequencer = MidiSystem.getSequencer(); // Opens the device, indicating that it should now acquire any system resources it requires and // become operational. sequencer.open(); // create a stream from a file InputStream is = new BufferedInputStream(new FileInputStream(new File(path + name))); // Sets the current sequence on which the sequencer operates. // The stream must point to MIDI file data. sequencer.setSequence(is); // Set looping if (loop) { sequencer.setLoopCount(LOOP_CONTINUOUSLY); } // Starts playback of the MIDI data in the currently loaded sequence. sequencer.start(); midiMap.put(name, sequencer); }
private synchronized void startMidi(InputStream bis, InputStream in) throws InvalidMidiDataException, MidiUnavailableException { Sequencer sequencer = null; Info info = null; // sequencer = MidiSystem.getSequencer( null ); sequencer = MidiSystem.getSequencer(); sequencer.open(); try { sequencer.setSequence(bis); } catch (IOException e) { throw new InvalidMidiDataException(e.getMessage()); } info = new Info(sequencer, in, null); infos.addElement(info); // fix for bug 4302884: Audio device is not released when AudioClip stops sequencer.addMetaEventListener(info); sequencer.start(); }