Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java sound

Name: Geronimo 2011-09-30 15:47

Hello, i was wondering if anyone could help me. I'm making a java game and i need a sound to start when i press a key and stop when i release it. What happens is that once the music starts it wont stop when i release :l
heres the code:
public void music() {
try {
InputStream in = new FileInputStream("C:/users/Usuario/Pictures/Game/nyan.wav");
AudioStream as = new AudioStream(in);

if (shooting == true && playingMusic == false) {
AudioPlayer.player.start(as);
playingMusic = true;
}
if (playingMusic == true && shooting == false) {
AudioPlayer.player. stop(as);
playingMusic = false;
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

the boolean playingMusic turns false when i release so the codes working, but the sound wont stop

Name: Anonymous 2011-09-30 18:45

I don't know Java beyond the basics, but I just did a google search and apparently you should be doing AudioPlayer.player.clear() instead of stop. I have no idea if this works or not, nor do I care, as you are clearly too stupid to use google.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List