import java.io.*;
import javax.sound.sampled.*;
public class Audio{
static Clip clip;
File soundFile = new
File("C:\\Users\\Hunter\\workspace\\Kal\\hi_score_entry.wav");
public boolean playing;
public static void main(String args[]){
//ignore what's in here
}
//play method
public void playsound() throws Exception {
AudioInputStream inputStream = AudioSystem.getAudioInputStream(soundFile);
clip = AudioSystem.getClip();
clip.open(inputStream);
playing=false;
if(playing==false){
clip.start();
playing = true;
}
else{
;
}
}
//placeholder for rewind method
public void rewsound() throws Exception{
}
//placeholder for pause method
public void pausesound() throws Exception{
clip.stop();
}
//placeholder for fastforward method
public void forwardsound() throws Exception{
}
}
I need the playsound function to play the .wav file when triggered by the clicking of the play button (obviously); however I need it to only do so once while the audio is playing; and then when the audio stops, it'll play again with another click.
It doesn't do that...it plays the file each time the button is clicked, leading to, well, boom.
ignore the pausesound() method for now, I'll get to that later. For now I just want the button to do as stated above.
EDIT: Updated the code; still having the same problem.
You are using non-premitive boolean -Boolean. Better you use the followign instead of
playing == false
: