changes audio engine

Probleme Audio File aus Package zu laden + evtl. änderung der klassen
This commit is contained in:
timbo
2014-11-13 23:25:30 +01:00
parent 876b1dc2b1
commit 47512d3fef
3 changed files with 35 additions and 5 deletions
+2 -1
View File
@@ -3,6 +3,7 @@ package de.heatup.audio;
public class Main {
public static void main(String[] args) {
new WavePlayer("<filetpath>").start();
//new WavePlayer("<filetpath>").start();
new WavePlayer("audiosample.wav").start();
}
}
+14
View File
@@ -0,0 +1,14 @@
package de.heatup.audio;
public class Play {
/**
* Praktisch wäre eine bindung von GameObject mit einem Sound
* dann könnte der entsprechende Sound einfach über das Object gespielt werden ohne jedesmal
* einen bestimmten pfand angeben zu müssen ?
* */
public void Play(String filename) {
}
}
+18 -3
View File
@@ -1,7 +1,9 @@
package de.heatup.audio;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
@@ -14,8 +16,8 @@ import javax.sound.sampled.UnsupportedAudioFileException;
public class WavePlayer extends Thread {
private String filename;
private Position curPosition;
//private File soundFile;
private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb
@@ -33,17 +35,30 @@ public class WavePlayer extends Thread {
curPosition = p;
}
//public WavePlayer(File soundFile) {
//this.soundFile = soundFile;
//}
public void run() {
/**
File soundFile = new File(filename);
if (!soundFile.exists()) {
System.err.println("Wave file not found: " + filename);
return;
}
} */
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
//audioInputStream = AudioSystem.getAudioInputStream(soundFile);
String path = "de/heatup/resources/audio/" + filename;
File f = new File(path);
if(!f.exists()) {
System.err.println("File not found: " + path);
return;
}
audioInputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(getClass().getResourceAsStream(path)));
} catch (UnsupportedAudioFileException e1) {
e1.printStackTrace();
return;