mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 09:09:46 +02:00
final audio, multiple sounds are possible and background loop should also work
This commit is contained in:
@@ -10,12 +10,7 @@ import javax.sound.sampled.LineListener;
|
|||||||
|
|
||||||
public class AudioPlayer {
|
public class AudioPlayer {
|
||||||
|
|
||||||
public AudioPlayer() {
|
public AudioPlayer() {}
|
||||||
/** oder anstelle pfad an die methode play,
|
|
||||||
* immer an die klasse und dann einen Player für jedes Soundfile
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void play(String file) {
|
public void play(String file) {
|
||||||
|
|
||||||
@@ -41,8 +36,6 @@ public class AudioPlayer {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ public class Main {
|
|||||||
|
|
||||||
SoundfileBomb b = new SoundfileBomb();
|
SoundfileBomb b = new SoundfileBomb();
|
||||||
|
|
||||||
//Sound s = new Sound(b.getPath());
|
|
||||||
//s.play();
|
|
||||||
|
|
||||||
AudioPlayer p = new AudioPlayer();
|
AudioPlayer p = new AudioPlayer();
|
||||||
p.play(b.getPath());
|
p.play(b.getPath());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user