package MiniMusicPlayer1;
import javax.sound.midi.*;
public class MiniMusicPlayer1 {
public static void main(String[] args) {
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
Sequence sequence = new Sequence(Sequence.PPQ, 4);
Track track = sequence.createTrack();
for (int i = 5; i < 61; i++) {
track.add(makeEvent(144, 1, i, 100, i));
track.add(makeEvent(128, 1, i, 100, i + 2));
}
sequencer.setSequence(sequence);
sequencer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
private static MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) {
MidiEvent event = null;
ShortMessage message = new ShortMessage();
try {
message.setMessage(comd, chan, one, two);
event = new MidiEvent(message, tick);
} catch (InvalidMidiDataException e) {
e.printStackTrace();
}
return event;
}
}
Java MiniMusicPlayer
最新推荐文章于 2022-06-28 16:57:19 发布