Example usage for javax.sound.midi MidiSystem getMidiFileFormat

List of usage examples for javax.sound.midi MidiSystem getMidiFileFormat

Introduction

In this page you can find the example usage for javax.sound.midi MidiSystem getMidiFileFormat.

Prototype

public static MidiFileFormat getMidiFileFormat(final File file) throws InvalidMidiDataException, IOException 

Source Link

Document

Obtains the MIDI file format of the specified File .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // From file/*w ww.  java 2 s  . c o m*/
    MidiFileFormat fformat = MidiSystem.getMidiFileFormat(new File("midifile"));

    // From URL
    //   fformat = MidiSystem.getMidiFileFormat(new URL("http://hostname/midifile"));

    // Get file format
    switch (fformat.getType()) {
    case 0:
        // mid
        break;
    case 1:
        // rmf
        break;
    }
}

From source file:SoundPlayer.java

public static void main(String[] args) throws IOException, UnsupportedAudioFileException,
        LineUnavailableException, MidiUnavailableException, InvalidMidiDataException {
    SoundPlayer player;/*from  ww w.j a  v a  2s.co  m*/

    File file = new File(args[0]); // This is the file we'll be playing
    // Determine whether it is midi or sampled audio
    boolean ismidi;
    try {
        // We discard the return value of this method; we just need to know
        // whether it returns successfully or throws an exception
        MidiSystem.getMidiFileFormat(file);
        ismidi = true;
    } catch (InvalidMidiDataException e) {
        ismidi = false;
    }

    // Create a SoundPlayer object to play the sound.
    player = new SoundPlayer(file, ismidi);

    // Put it in a window and play it
    JFrame f = new JFrame("SoundPlayer");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(player, "Center");
    f.pack();
    f.setVisible(true);
}