Skip to content

Commit 0fa20a0

Browse files
committed
Fix instant crashing #21
Problems with resolving class input streams MP3 May not be supported on adoptOpenJDK
1 parent 1295a77 commit 0fa20a0

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

res/music/Towards The End.wav

31.3 MB
Binary file not shown.

res/music/small.wav

11.4 KB
Binary file not shown.

src/com/redomar/game/audio/AudioHandler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
import javax.sound.sampled.*;
77
import java.io.File;
8+
import java.util.Arrays;
89

910

1011
public class AudioHandler {
1112

1213
private Clip clip;
1314
private boolean active = false;
14-
private Printing p = new Printing();
15+
private final Printing p = new Printing();
1516

1617
public AudioHandler(String path){
1718
check(path);
@@ -23,7 +24,7 @@ public AudioHandler(File file){
2324

2425
private void check(String path){
2526
try {
26-
if(path != ""){
27+
if(!path.equals("")){
2728
initiate(path);
2829
} else {
2930
throw new NullPointerException();
@@ -36,22 +37,22 @@ private void check(String path){
3637

3738
private void initiate(String path){
3839
try{
39-
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream(path));
40-
AudioFormat baseformat = audioInputStream.getFormat();
40+
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(AudioHandler.class.getResourceAsStream(path));
41+
AudioFormat baseFormat = audioInputStream.getFormat();
4142
AudioFormat decodeFormat = new AudioFormat(
4243
AudioFormat.Encoding.PCM_SIGNED,
43-
baseformat.getSampleRate(), 16,
44-
baseformat.getChannels(),
45-
baseformat.getChannels() * 2,
46-
baseformat.getSampleRate(),
44+
baseFormat.getSampleRate(), 16,
45+
baseFormat.getChannels(),
46+
baseFormat.getChannels() * 2,
47+
baseFormat.getSampleRate(),
4748
false
4849
);
4950
AudioInputStream decodedAudioInputStream = AudioSystem.getAudioInputStream(
5051
decodeFormat, audioInputStream);
5152
clip = AudioSystem.getClip();
5253
clip.open(decodedAudioInputStream);
5354
} catch (Exception e){
54-
System.err.println(e.getStackTrace());
55+
System.err.println(Arrays.toString(e.getStackTrace()));
5556
p.print("Audio Failed to initiate", PrintTypes.ERROR);
5657
}
5758
}

src/com/redomar/game/entities/projectiles/Small.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class Small extends Projectile{
1111

1212
public static final int FIRE_RATE = 10;
13-
private static final File smallShot = new File("/music/small.mp3");
13+
private static final File smallShot = new File("/music/small.wav");
1414
private static AudioHandler smallSound;
1515

1616
public Small(LevelHandler level, int x, int y, double dir) {

src/com/redomar/game/level/LevelHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public int compare(Node n0, Node n1) {
6161

6262
private void loadLevelFromFile() {
6363
try {
64-
this.image = ImageIO.read(Level.class.getResource(this.imagePath));
64+
this.image = ImageIO.read(LevelHandler.class.getResource(this.imagePath));
6565
this.setWidth(image.getWidth());
6666
this.setHeight(image.getHeight());
6767
tiles = new byte[getWidth() * getHeight()];
6868
this.loadTiles();
69-
} catch (IOException e) {
69+
} catch (IOException e ){
7070
e.printStackTrace();
7171
}
7272
}

src/com/redomar/game/menu/Menu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void play() {
4949
splash.requestFocus();
5050
splash.splashOn();
5151
splash.setProgress(20, "Loading Music");
52-
Game.setBackgroundMusic(new AudioHandler("/music/Towards The End.mp3"));
52+
Game.setBackgroundMusic(new AudioHandler("/music/Towards The End.wav"));
5353
splash.setProgress(50, "Setting Volume");
5454
Game.getBackgroundMusic().setVolume(-20);
5555
splash.setProgress(60, "Acquiring data: Multiplayer");

0 commit comments

Comments
 (0)