Playing Streaming Midi Audio - Java Media

Java examples for Media:Audio

Description

Playing Streaming Midi Audio

Demo Code

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequencer;

public class Main {

  public void main(String[] argv) {
    try {/*from  w ww  .  ja  v  a 2s . c o m*/
      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.open();

      InputStream is = new BufferedInputStream(new FileInputStream(new File("midifile")));

      is = new BufferedInputStream(new URL("http://hostname/rmffile").openStream());

      sequencer.setSequence(is);

      sequencer.start();
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    } catch (MidiUnavailableException e) {
    } catch (InvalidMidiDataException e) {
    }
  }
}

Related Tutorials