feat: preview of next shape
This commit is contained in:
@@ -4,6 +4,7 @@ import eu.midnightdust.yaytris.Settings;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -23,7 +24,7 @@ public class SoundUtil {
|
||||
|
||||
// Adapted from: https://www.baeldung.com/java-play-sound
|
||||
public static void playSoundClip(String fileLocation) {
|
||||
try (AudioInputStream stream = AudioSystem.getAudioInputStream(SoundUtil.class.getResource(fileLocation))) { // FIXME: Support audio files from JAR. File streams won't work here for some reason.
|
||||
try (AudioInputStream stream = AudioSystem.getAudioInputStream(getResource(fileLocation))) { // FIXME: Support audio files from JAR. File streams won't work here for some reason.
|
||||
AudioFormat format = stream.getFormat();
|
||||
DataLine.Info info = new DataLine.Info(Clip.class, format);
|
||||
|
||||
@@ -37,6 +38,10 @@ public class SoundUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static URL getResource(String fileLocation) {
|
||||
return SoundUtil.class.getResource(fileLocation);
|
||||
}
|
||||
|
||||
// Adapted from: https://stackoverflow.com/a/40698149
|
||||
private static void setVolume(Line line, int volume) {
|
||||
if (volume < 0 || volume > 100)
|
||||
@@ -68,7 +73,7 @@ public class SoundUtil {
|
||||
|
||||
// Adapted from: https://www.baeldung.com/java-play-sound
|
||||
private void playMusic(String fileLocation) {
|
||||
try (AudioInputStream stream = AudioSystem.getAudioInputStream(SoundUtil.class.getResource(fileLocation))) {
|
||||
try (AudioInputStream stream = AudioSystem.getAudioInputStream(getResource(fileLocation))) {
|
||||
AudioFormat format = stream.getFormat();
|
||||
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user