Java 怎么加载和播放MIDI音频

2019年7月29日20:09:49Java 怎么加载和播放MIDI音频已关闭评论 514 777字阅读2分35秒

1.简介

Java 怎么加载和播放MIDI音频?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */
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.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;

public class Main {
  public static void main(String[] argv) throws Exception {
    try {
      
      Sequence sequence = MidiSystem.getSequence(new File("midifile"));

      
      sequence = MidiSystem.getSequence(new URL("http:

      
      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.open();
      sequencer.setSequence(sequence);

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

 
编程十万个怎么办