mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:29:45 +02:00
added Classloader without exception handling to audio
This commit is contained in:
@@ -3,7 +3,7 @@ package de.heatup.audio;
|
|||||||
public class AudioFiles {
|
public class AudioFiles {
|
||||||
|
|
||||||
//base path
|
//base path
|
||||||
private static final String basePath = "src/de/heatup/resources/audio/";
|
private static final String basePath = "de/heatup/resources/audio/";
|
||||||
|
|
||||||
//sound files
|
//sound files
|
||||||
private String Invaders;
|
private String Invaders;
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ import javax.sound.sampled.LineListener;
|
|||||||
|
|
||||||
public class AudioPlayer {
|
public class AudioPlayer {
|
||||||
|
|
||||||
public AudioPlayer() {}
|
private ClassLoader cl;
|
||||||
|
|
||||||
|
public AudioPlayer() {
|
||||||
|
this.cl = Thread.currentThread().getContextClassLoader();
|
||||||
|
}
|
||||||
|
|
||||||
/** plays a file once */
|
/** plays a file once */
|
||||||
public void play(String file) {
|
public void play(String file) {
|
||||||
@@ -26,13 +30,17 @@ public class AudioPlayer {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
File f = new File(file);
|
File f = new File(file);
|
||||||
if(!f.exists()) {
|
if(!f.exists()) {
|
||||||
System.out.println("File not found: " + f.getAbsolutePath());
|
System.out.println("File not found: " + f.getAbsolutePath());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
clip.open(AudioSystem.getAudioInputStream(f));
|
|
||||||
|
|
||||||
|
clip.open(AudioSystem.getAudioInputStream(cl.getResourceAsStream(file)));
|
||||||
clip.start();
|
clip.start();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -54,13 +62,15 @@ public class AudioPlayer {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
File f = new File(file);
|
File f = new File(file);
|
||||||
if(!f.exists()) {
|
if(!f.exists()) {
|
||||||
System.out.println("File not found: " + f.getAbsolutePath());
|
System.out.println("File not found: " + f.getAbsolutePath());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
clip.open(AudioSystem.getAudioInputStream(f));
|
clip.open(AudioSystem.getAudioInputStream(cl.getResourceAsStream(file)));
|
||||||
clip.loop(clip.LOOP_CONTINUOUSLY);
|
clip.loop(clip.LOOP_CONTINUOUSLY);
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user