Hey rune-server this is my first tutorial and its pretty simple to be honest. I am not going to spoonfeed because this is so simple to add. If you can't add it, there is something wrong with you tbh. Well lets get started!
First make a new class called Music.java and place it in your client folder with all the other files client.java, sprite.java, etc.
Code:
import java.io.*;
import javax.sound.sampled.*;
import sign.*;
import java.util.*;
public class Music {
private static Clip clip;
//use to choose a random song
public static void playRandom() {
Random random = new Random();
int play = random.nextInt(4);
Music("jingle"+play);
}
//gets file by name and opens audio system
public static void Music(String soundFileName) {
String dir = signlink.findcachedir();
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(dir+"/Music/"+soundFileName).getAbsoluteFile());
clip = AudioSystem.getClip();
clip.open(audioInputStream);
play();
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
}
}
//starts playing the actual music
public static void play() {
if (clip.isRunning()) {
clip.stop();
}
clip.setFramePosition(0);
clip.start();
}
//stops the music if needed
public static void stop() {
clip.stop();
clip.setFramePosition(0);
clip.close();
}
}
Thats it basically for the music system. Now to play a song all you do is Music.Music(filename);
Example:
Download Little bird tune:
UPLOAD.EE - Download sound5.wav
Now create a folder in your cache called "Music" and place that file in there.
Now open client.java and find "loggedIn = true" and under add it under it
Code:
Music.Music("sound5.wav");
Thanks for reading guys and thank me or rep if you use =)