Unfortunately I tried to use this code above and it didn’t work, I only used the loop command to repeat even if I took it from here, I found another one that worked. I’m gonna send it down like mine did.
package jogo;
import java.io.File;
import javax.sound.sampled.*;
public class AudioAcerto {
void AudioAcerto() { //Método AudioAcerto para chamar na classe executavel.
try {
//URL do som que no caso esta no pendrive, mais ainda é uma fase de teste.
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("G:\\ETEC\\2º MODULO\\4 QUINTA FEIRA\\PTCC\\EtecQuiz\\Musicas\\Urban-Future.wav").getAbsoluteFile());
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
clip.loop(Clip.LOOP_CONTINUOUSLY); //Para repetir o som.
} catch (Exception ex) {
System.out.println("Erro ao executar SOM!");
ex.printStackTrace();
}
}
}
From here is the executable class, unless they will put the audio in the same class without creating method.
package jogo;
public class Teste { //Classe executavel
public static void main(String[] args) throws InterruptedException { //Executável do jogo
AudioAcerto y = new AudioAcerto(); // Chamando a classe aonde está o audio.
y.AudioAcerto (); // Chamando o método do audio
}
}
Welcome to Stackoverflow! Please explain the problem better, and if possible include a example of code that reproduces what is happening, because your question is too wide. See Help Center How to Ask.
– Jorge B.
I understood that the final question "how do I include a warning sound" is what the AP really wants to know. If that’s all, it doesn’t seem like a broad question.
– Luiz Vieira
Can someone who voted to close explain what is too broad here? By the way, I voted to reopen.
– Victor Stafusa