Hello rune-server this is my first post.
this is a simple midi player that plays midi files from the cache and goes right into SignLink.java in your server works for most pi servers but might need some modifications. you need a couple of sound imports which i forgot.
start out by importing these two
Code:
import javax.sound.sampled.*;
import javax.sound.midi.*;
now somewhere add this method
Code:
public static void playMidi(String location) {
music = null;
synthesizer = null;
sequence = null;
File midiFile = new File(findcachedir() + "/Music/" + location + ".mid");
try {
sequence = MidiSystem.getSequence(midiFile);
music = MidiSystem.getSequencer();
music.open();
music.setSequence(sequence);
} catch (Exception e) {
System.err.println("Problem loading MIDI file.");
e.printStackTrace();
return;
}
if (music instanceof Synthesizer) {
synthesizer = (Synthesizer) music;
} else {
try {
synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
if (synthesizer.getDefaultSoundbank() == null) {
music.getTransmitter().setReceiver(MidiSystem.getReceiver());
} else {
music.getTransmitter().setReceiver(synthesizer.getReceiver());
}
} catch (Exception e) {
e.printStackTrace();
return;
}
}
music.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
music.start();
}
this plays midi files with SignLink.playMidi(filename); the it automatically adds the .mid extension. plays from cachedir/Music/ and plays filename.mid inside of that folder.
this can be added to startup method in client.java after the client downloads the cache to play the login music. thats all good and everything but what happens when you want to stop it at login. add this to signlink.java as well
Code:
public static void stopMidi() {
try {
if ((music == null) || (!music.isRunning())) return;
music.stop();
music.close();
}
catch (Exception e) {
System.err.println("MidiPlayer: " + e);
}
music = null;
}
this stops the song with SignLink.stopMidi();
so at login you stop the current song and then play the next song you want to play.
this is just a simple tutorial. i got this far but idk how to make it play diffrent songs from the songs tab. you can make client sided commands to change the song but thats all i know.
if anyone has a tutorial out there on how to make server packets change the song please tell me. i dont know if this requires any constants but just use eclispe or and ide and it should tell you want you're missing
*edit*
you need to add
Code:
public static Sequencer music = null;
public static Sequence sequence = null;
public static Synthesizer synthesizer = null;
somewhere in there