/** * Gets a transmitter for this device (which is also added to the internal list * * @see javax.sound.midi.MidiDevice#getTransmitter() * * @return a transmitter for this device * */ @Override public Transmitter getTransmitter() throws MidiUnavailableException { throw new MidiUnavailableException("CoreMidiDestination has no sources (Transmitters)"); }
/** * Creates and returns a MIDI Receiver for use with this Device * * @return the created receiver * * @see javax.sound.midi.MidiDevice#getReceiver() * */ @Override public Receiver getReceiver() throws MidiUnavailableException { throw new MidiUnavailableException("CoreMidiSource has no receivers"); }
/** Creates a new Transmitter object associated with this instance. * In this implementation, an unlimited number of Transmitters * per MidiDevice can be created. */ public Transmitter getTransmitter() throws MidiUnavailableException { if (! getUseTransmitter()) { throw new MidiUnavailableException("Transmitters are not supported by this device"); } return new TTransmitter(); }
/** Creates a new Receiver object associated with this instance. * In this implementation, an unlimited number of Receivers * per MidiDevice can be created. */ public Receiver getReceiver() throws MidiUnavailableException { if (! getUseReceiver()) { throw new MidiUnavailableException("Receivers are not supported by this device"); } return new TReceiver(); }
/** Creates a new Receiver object associated with this instance. * In this implementation, an unlimited number of Receivers * per MidiDevice can be created. */ public Receiver getReceiver() throws MidiUnavailableException { if (! getUseReceiver()) { throw new MidiUnavailableException("Receivers are not supported by this device"); } return new TReceiver(); }
/** Creates a new Transmitter object associated with this instance. * In this implementation, an unlimited number of Transmitters * per MidiDevice can be created. */ public Transmitter getTransmitter() throws MidiUnavailableException { if (! getUseTransmitter()) { throw new MidiUnavailableException("Transmitters are not supported by this device"); } return new TTransmitter(); }
/** * Opens the Core MIDI Device * * @throws MidiUnavailableException if the MIDI system cannot be used * */ @Override public void open() throws MidiUnavailableException { if (isOpen.compareAndSet(false, true)) { try { // Create the input port if not already created if (input.get() == null) { input.set(CoreMidiDeviceProvider.getMIDIClient().inputPortCreate("Core Midi Provider Input")); } // And connect to it input.get().connectSource(this); // Get the system time in microseconds startTime = this.getMicroSecondTime(); } catch (CoreMidiException e) { e.printStackTrace(); throw new MidiUnavailableException(e.getMessage()); } } }
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("music.mid"); Sequence Seq = MidiSystem.getSequence(is); sequencer.setSequence(Seq); sequencer.start(); } catch (Exception e) { e.printStackTrace(); } } here is a sample code that shows you how to play MIDI files in your java program, hope it helps