final audio, multiple sounds are possible and background loop should also work

This commit is contained in:
shebang
2014-12-09 15:18:42 +01:00
parent f91d7f5a2f
commit a801e601d1
3 changed files with 5 additions and 66 deletions
+1 -8
View File
@@ -10,12 +10,7 @@ import javax.sound.sampled.LineListener;
public class AudioPlayer {
public AudioPlayer() {
/** oder anstelle pfad an die methode play,
* immer an die klasse und dann einen Player für jedes Soundfile
*/
}
public AudioPlayer() {}
public void play(String file) {
@@ -42,7 +37,5 @@ public class AudioPlayer {
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
+2 -3
View File
@@ -6,10 +6,9 @@ public class Main {
SoundfileBomb b = new SoundfileBomb();
//Sound s = new Sound(b.getPath());
//s.play();
AudioPlayer p = new AudioPlayer();
p.play(b.getPath());
}
}
-53
View File
@@ -1,53 +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 class Sound {
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 {
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}