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: code fairy 2011-09-30 17:56

Since you're too FUCKING newb to (1) format your code, and (2) use [code] tags, I will do it for you.

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();
                }
        }
}


Anyways, it's not like we can see what happens when you press/release a key so there's nothing we can do with this code.

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