So, im making a midi system for e 2-d java game on developing and so far i was able to make a simple midi file that plays + stops, but i've been trying to play with volume and fading but it doesn't seem to want to work right.
Here's my class file:
package sign;
import java.io.*;
import javax.sound.midi.*;
public class Midi {
private static Sequencer sequencer = null;
public void play(String filename) {
play(filename,false);
}
public static void play(String filename, boolean loop) {
try {
stop();
sequencer = MidiSystem.getSequencer();
File midiFile = new File(filename);
sequencer.setSequence(MidiSystem.getSequence(midiFile));
if (loop)
sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
sequencer.open();
sequencer.start();
} catch (Exception e) {
System.err.println("MidiPlayer: " + e);
sequencer = null;
}
}
public static Sequencer getSequencer() {
return sequencer;
}
public static void stop() {
try {
if ((sequencer == null) || (!sequencer.isRunning())) return;
sequencer.stop();
sequencer.close();
}
catch (Exception e) {
System.err.println("MidiPlayer: " + e);
}
sequencer = null;
}
}
What i'm asking is, can anyone give me a explanation on how to impliment volume + fading with this file?.
I've tried some methods of fading + volume control but they always crash my game because they require some ridiculously older midi device for it to work.