mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:29:45 +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) {
|
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.LineUnavailableException;
|
||||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||||
|
|
||||||
public enum Sound {
|
public class Sound {
|
||||||
BOMB("src/de/heatup/resources/audio/" + "bomb.wav");
|
|
||||||
|
|
||||||
private Clip clip;
|
private Clip clip;
|
||||||
|
|
||||||
@@ -46,12 +45,8 @@ public enum Sound {
|
|||||||
|
|
||||||
public void play() {
|
public void play() {
|
||||||
try {
|
try {
|
||||||
new Thread() {
|
|
||||||
public void run() {
|
|
||||||
clip.start();
|
clip.start();
|
||||||
}
|
} catch (Exception e) {
|
||||||
}.start();
|
|
||||||
} catch(Throwable e) {
|
|
||||||
e.printStackTrace();
|
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