mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 09:09:46 +02:00
new AudioPlayer tested on windows
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package de.heatup.audio;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.sound.sampled.Line;
|
||||
import javax.sound.sampled.LineEvent;
|
||||
import javax.sound.sampled.LineListener;
|
||||
|
||||
public class AudioPlayer {
|
||||
|
||||
public AudioPlayer(/** String file */) {
|
||||
///this.file = file;
|
||||
}
|
||||
|
||||
public void play(String file) {
|
||||
|
||||
try {
|
||||
final Clip clip = (Clip)AudioSystem.getLine(new Line.Info(Clip.class));
|
||||
clip.addLineListener(new LineListener() {
|
||||
|
||||
@Override
|
||||
public void update(LineEvent event) {
|
||||
if(event.getType() == LineEvent.Type.STOP)
|
||||
clip.close();
|
||||
}
|
||||
});
|
||||
|
||||
clip.open(AudioSystem.getAudioInputStream(new File(file)));
|
||||
clip.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,12 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Sound.BOMB.play();
|
||||
SoundfileBomb b = new SoundfileBomb();
|
||||
|
||||
//Sound s = new Sound(b.getPath());
|
||||
//s.play();
|
||||
|
||||
AudioPlayer p = new AudioPlayer();
|
||||
p.play(b.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ import javax.sound.sampled.Line;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
public enum Sound {
|
||||
BOMB("src/de/heatup/resources/audio/" + "bomb.wav");
|
||||
public class Sound {
|
||||
|
||||
private Clip clip;
|
||||
|
||||
@@ -46,12 +45,8 @@ public enum Sound {
|
||||
|
||||
public void play() {
|
||||
try {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
clip.start();
|
||||
}
|
||||
}.start();
|
||||
} catch(Throwable e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package de.heatup.audio;
|
||||
|
||||
public class SoundfileBomb {
|
||||
private String path;
|
||||
|
||||
public SoundfileBomb() {
|
||||
this.path = "src/de/heatup/resources/audio/" + "bomb.wav";
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user