mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-02 16:49:03 +00:00
Merge pull request #608
* fix: Remove Oracle JRE dependency for sound effects
This commit is contained in:
@@ -1,23 +1,18 @@
|
|||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
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!
|
import javax.sound.sampled.*;
|
||||||
|
|
||||||
public class SoundPlayer implements Runnable {
|
public class SoundPlayer implements Runnable {
|
||||||
|
|
||||||
private AudioInputStream stream;
|
private AudioInputStream stream;
|
||||||
private DataLine.Info info;
|
private DataLine.Info info;
|
||||||
private Clip sound;
|
private SourceDataLine sound;
|
||||||
|
|
||||||
private InputStream soundStream;
|
private InputStream soundStream;
|
||||||
private Thread player;
|
private Thread player;
|
||||||
private int delay;
|
private int delay;
|
||||||
private int soundLevel;
|
private int soundLevel;
|
||||||
private InputStream arg0;
|
|
||||||
public static int volume;
|
public static int volume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,22 +37,37 @@ public class SoundPlayer implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
AudioPlayer.player.start(arg0);
|
|
||||||
stream = AudioSystem.getAudioInputStream(soundStream);
|
stream = AudioSystem.getAudioInputStream(soundStream);
|
||||||
info = new DataLine.Info(Clip.class, stream.getFormat());
|
|
||||||
sound = (Clip) AudioSystem.getLine(info);
|
AudioFormat format = stream.getFormat();
|
||||||
sound.open(stream);
|
info = new DataLine.Info(SourceDataLine.class, format);
|
||||||
|
sound = (SourceDataLine) AudioSystem.getLine(info);
|
||||||
|
sound.open(format);
|
||||||
|
|
||||||
FloatControl volume = (FloatControl) sound.getControl(FloatControl.Type.MASTER_GAIN);
|
FloatControl volume = (FloatControl) sound.getControl(FloatControl.Type.MASTER_GAIN);
|
||||||
volume.setValue(getDecibels(soundLevel - getVolume()));
|
volume.setValue(getDecibels(soundLevel - getVolume()));
|
||||||
if (delay > 0) {
|
if (delay > 0) {
|
||||||
Thread.sleep(delay);
|
Thread.sleep(delay);
|
||||||
}
|
}
|
||||||
sound.start();
|
sound.start();
|
||||||
while (sound.isActive()) {
|
|
||||||
Thread.sleep(250);
|
int nBytesRead = 0;
|
||||||
|
int EXTERNAL_BUFFER_SIZE = 524288;
|
||||||
|
byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
|
||||||
|
try {
|
||||||
|
while (nBytesRead != -1) {
|
||||||
|
nBytesRead = stream.read(abData, 0, abData.length);
|
||||||
|
if (nBytesRead >= 0) {
|
||||||
|
sound.write(abData, 0, nBytesRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
sound.drain();
|
||||||
|
sound.close();
|
||||||
}
|
}
|
||||||
Thread.sleep(10000);
|
|
||||||
sound.close();
|
|
||||||
stream.close();
|
stream.close();
|
||||||
player.interrupt();
|
player.interrupt();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user