mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 09:09:46 +02:00
changes audio engine
Probleme Audio File aus Package zu laden + evtl. änderung der klassen
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -31,19 +33,32 @@ public class WavePlayer extends Thread {
|
||||
public WavePlayer(String wavfile, Position p) {
|
||||
filename = wavfile;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user