Determining the File Format of a Midi Audio File - Java Media

Java examples for Media:Audio

Description

Determining the File Format of a Midi Audio File

Demo Code

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiFileFormat;
import javax.sound.midi.MidiSystem;

public class Main {
  public static void main(String[] args) throws Exception {
    try {//from ww  w  . j a  v a  2  s.c o  m
      MidiFileFormat fformat = MidiSystem.getMidiFileFormat(new File("midifile"));
      fformat = MidiSystem
          .getMidiFileFormat(new URL("http://hostname/midifile"));

      switch (fformat.getType()) {
      case 0:
        // mid
        break;
      case 1:
        // rmf
        break;
      }
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    } catch (InvalidMidiDataException e) {
      // File format is not supported.
    }
  }
}

Related Tutorials