mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 08:39:04 +00:00
Make project setup easier with Maven (#411)
* Remove a bunch of .ideas and class files to see if it makes the setup easier * remove some .idea's and imkls * Remove a ton of .class files * [TASK] Switched to maven instead of gradle * [TASK] Added target to gitignore * Remove ignored files * [TASK] Fixed file_server source * [TASK] Fixed client source * [BUGFIX] Main Class * [BUGFIX] Fixed SLF4J * [TASK] Server Libs cleanup * Update setup guide/debug * Maven cli compile instructions * [TASK] Jar building * Update runServer and runFileServer.sh Co-authored-by: Sandro Coutinho <sandro@farrelltech.org>
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import java.io.InputStream;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.sound.sampled.DataLine;
|
||||
import javax.sound.sampled.FloatControl;
|
||||
|
||||
import sun.audio.AudioPlayer; //Note! If you see a compile error here, make sure you set your JDK to Java 8!
|
||||
|
||||
public class SoundPlayer implements Runnable {
|
||||
|
||||
private AudioInputStream stream;
|
||||
private DataLine.Info info;
|
||||
private Clip sound;
|
||||
|
||||
private InputStream soundStream;
|
||||
private Thread player;
|
||||
private int delay;
|
||||
private int soundLevel;
|
||||
private InputStream arg0;
|
||||
public static int volume;
|
||||
|
||||
/**
|
||||
* Initializes the sound player.
|
||||
* @param stream
|
||||
* @param level
|
||||
* @param delay
|
||||
*/
|
||||
public SoundPlayer(InputStream stream, int level, int delay) {
|
||||
if (level == 0 || volume == 4 || level - volume <= 0) {
|
||||
return;
|
||||
}
|
||||
this.soundStream = stream;
|
||||
this.soundLevel = level;
|
||||
this.delay = delay;
|
||||
player = new Thread(this);
|
||||
player.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the sound.
|
||||
*/
|
||||
public void run() {
|
||||
try {
|
||||
AudioPlayer.player.start(arg0);
|
||||
stream = AudioSystem.getAudioInputStream(soundStream);
|
||||
info = new DataLine.Info(Clip.class, stream.getFormat());
|
||||
sound = (Clip) AudioSystem.getLine(info);
|
||||
sound.open(stream);
|
||||
FloatControl volume = (FloatControl) sound.getControl(FloatControl.Type.MASTER_GAIN);
|
||||
volume.setValue(getDecibels(soundLevel - getVolume()));
|
||||
if (delay > 0) {
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
sound.start();
|
||||
while (sound.isActive()) {
|
||||
Thread.sleep(250);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
sound.close();
|
||||
stream.close();
|
||||
player.interrupt();
|
||||
} catch (Exception e) {
|
||||
player.interrupt();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the client's volume level.
|
||||
* @param level
|
||||
*/
|
||||
public static void setVolume(int level) {
|
||||
volume = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client's volume level.
|
||||
*/
|
||||
public static int getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the decibels for a given volume level.
|
||||
* @param level
|
||||
* @return
|
||||
*/
|
||||
public float getDecibels(int level) {
|
||||
switch (level) {
|
||||
case 0: // 4 in player options
|
||||
return (float) -1.0f;
|
||||
case 1: // 3
|
||||
return (float) -5.0f;
|
||||
case 2: // 2
|
||||
return (float) -10.0f;
|
||||
case 3: // 1
|
||||
return (float) -15.0f;
|
||||
case 4: // off
|
||||
return (float) -100.0f;
|
||||
default:
|
||||
return (float) 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user