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 class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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;
|
package de.heatup.audio;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.sound.sampled.AudioFormat;
|
import javax.sound.sampled.AudioFormat;
|
||||||
import javax.sound.sampled.AudioInputStream;
|
import javax.sound.sampled.AudioInputStream;
|
||||||
import javax.sound.sampled.AudioSystem;
|
import javax.sound.sampled.AudioSystem;
|
||||||
@@ -14,8 +16,8 @@ import javax.sound.sampled.UnsupportedAudioFileException;
|
|||||||
public class WavePlayer extends Thread {
|
public class WavePlayer extends Thread {
|
||||||
|
|
||||||
private String filename;
|
private String filename;
|
||||||
|
|
||||||
private Position curPosition;
|
private Position curPosition;
|
||||||
|
//private File soundFile;
|
||||||
|
|
||||||
private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb
|
private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb
|
||||||
|
|
||||||
@@ -31,19 +33,32 @@ public class WavePlayer extends Thread {
|
|||||||
public WavePlayer(String wavfile, Position p) {
|
public WavePlayer(String wavfile, Position p) {
|
||||||
filename = wavfile;
|
filename = wavfile;
|
||||||
curPosition = p;
|
curPosition = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public WavePlayer(File soundFile) {
|
||||||
|
//this.soundFile = soundFile;
|
||||||
|
//}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
|
/**
|
||||||
File soundFile = new File(filename);
|
File soundFile = new File(filename);
|
||||||
if (!soundFile.exists()) {
|
if (!soundFile.exists()) {
|
||||||
System.err.println("Wave file not found: " + filename);
|
System.err.println("Wave file not found: " + filename);
|
||||||
return;
|
return;
|
||||||
}
|
} */
|
||||||
|
|
||||||
AudioInputStream audioInputStream = null;
|
AudioInputStream audioInputStream = null;
|
||||||
try {
|
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) {
|
} catch (UnsupportedAudioFileException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user