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

Pages: 1-

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 16:08

please?

Name: Anonymous 2011-09-30 16:13

fail. GTFO

Name: Anonymous 2011-09-30 16:26

:(

Name: Anonymous 2011-09-30 16:30

ENTERPRISE QUALITY
READ SICP
JAVA SUCKS
SLACKWARE SUPREMACY
GC IS SHIT

Name: Anonymous 2011-09-30 17:09

oh yeah... and:

My mom.

Name: Anonymous 2011-09-30 17:11

>>5 LMAO i see u saw my thread

Name: Anonymous 2011-09-30 17:18

>>5
You stole my post, ``faggot''.

Name: Anonymous 2011-09-30 17:24

so nobody can help? :C

Name: Anonymous 2011-09-30 17:50

please T-T

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.

Name: Anonymous 2011-09-30 18:03

>>11 the sound starts when i press space key, and playingMusic changes to true.
when i release space playingMusic turns false, however music keeps playing.

Also, thanks

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.

Name: >>13 2011-09-30 18:46

Also your code sucks.

Name: Anonymous 2011-09-30 19:25

>>13 that isnt even a command

Name: Anonymous 2011-09-30 20:24

>>AudioPlayer.player. stop(as);

No space?            ^^

Name: Anonymous 2011-10-01 22:56

>>15
I believe the word you were looking for is method.

Name: Anonymous 2011-10-02 7:10

ENTERPRISE QUALITY!!

Name: Anonymous 2011-10-02 12:08

>>17
No. The correct word is Haskell.

Name: Anonymous 2011-10-02 17:45

Java programmers are this retarded.

Name: Anonymous 2011-10-02 18:44

Who imagined the sound of freshly roasted beans being poured into a coffee pot upon reading the thread title?

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