mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 09:59:45 +02:00
Merge branch 'master' of github.com:jokerx3/prp
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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() {}
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
File f = new File(file);
|
||||
if(!f.exists()) {
|
||||
System.out.println("File not found: " + f.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
clip.open(AudioSystem.getAudioInputStream(f));
|
||||
clip.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,11 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Sound.BOMB.play();
|
||||
SoundfileBomb b = new SoundfileBomb();
|
||||
|
||||
AudioPlayer p = new AudioPlayer();
|
||||
p.play(b.getPath());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package de.heatup.audio;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
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");
|
||||
|
||||
private Clip clip;
|
||||
|
||||
Sound(String soundFileName) {
|
||||
|
||||
File f = new File(soundFileName);
|
||||
if(!f.exists()) {
|
||||
System.err.println("File not found : " + f.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Line.Info linfo = new Line.Info(Clip.class);
|
||||
Line line = AudioSystem.getLine(linfo);
|
||||
|
||||
clip = (Clip) line;
|
||||
AudioInputStream inputStream = AudioSystem.getAudioInputStream(f);
|
||||
|
||||
clip.open(inputStream);
|
||||
|
||||
} catch(UnsupportedAudioFileException e) {
|
||||
e.printStackTrace();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch(LineUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
try {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
clip.start();
|
||||
}
|
||||
}.start();
|
||||
} catch(Throwable 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