Hi!
Ich möchte gerne etwas Sound in meinem Programm abspielen.
Klappt leider noch nicht so ganz, wie ich mir das vorstelle. Ich kann ca. eine halbe Sekunde was hören und dann ist finito.
Das Problem ist wohl, das das Programm beendet wird, bevor das Sound komplett abgespielt wurde.
Ich vermute mal, das ich am Ende meiner main()-Methode einfach nur einen Befehl a la "Warte, bis alle Threads beendet sind" einbauen muss.
Ich möchte gerne etwas Sound in meinem Programm abspielen.
Klappt leider noch nicht so ganz, wie ich mir das vorstelle. Ich kann ca. eine halbe Sekunde was hören und dann ist finito.
Das Problem ist wohl, das das Programm beendet wird, bevor das Sound komplett abgespielt wurde.
Code:
import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
public class PlaySound extends Thread {
public static void main(String[] args) throws InterruptedException {
PlaySound playSound = new PlaySound();
playSound.start();
}
public void run() {
// Sound File
String file = "Ee_rev.wav";
String path = "C:\\WINDOWS\\Media\\";
String soundFileName = path + file;
File soundFile = new File(soundFileName);
// play Sound
try {
AudioClip sound = Applet.newAudioClip(soundFile.toURL());
sound.play();
} catch (Exception tmpE) {
System.err.println(tmpE);
}
}
}
Ich vermute mal, das ich am Ende meiner main()-Methode einfach nur einen Befehl a la "Warte, bis alle Threads beendet sind" einbauen muss.