This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Quit audio before application exits. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Quit audio before application exits." Watch "Quit audio before application exits." New topic
Author

Quit audio before application exits.

Braden Steffaniak
Greenhorn

Joined: Jun 03, 2011
Posts: 15
In my application, I have audio running thrughout the whole time the application is open.

However, whenever I exit the application, my computer makes a noise that makes me think that something went wrong. I dont really know how to explain it other than it is just one tone and it does not sound like the audio that I had playing.

Is there a way to make this sound not occur? Should I stop the audio from playing before the application exits?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19214

How are you playing the audio?


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Braden Steffaniak
Greenhorn

Joined: Jun 03, 2011
Posts: 15
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19214

I don't know how your application is exited, but unless you call System.exit, the sound playing threads will continue until they end. I'd definitely stop them. Also, you should make the playing variable volatile, as it's clearly meant to be shared among multiple threads.

I don't see any GUI related code here, so I'll move this thread to Java in General.
Braden Steffaniak
Greenhorn

Joined: Jun 03, 2011
Posts: 15
I use system.exit(0) to exit the program when the x button is pressed. (and I changed playing to volatile) But it still makes the sound.
Braden Steffaniak
Greenhorn

Joined: Jun 03, 2011
Posts: 15
I have now added this line to my code, and it runs right before the program exits.

However, it makes a very... very loud annoying sound that scares the crap out of me. And even after the program has exited, it will repeat the sound a few times after when you try to play any audio.

Heres the code:



It is in the Sound.class as seen in the code in my second post.
Braden Steffaniak
Greenhorn

Joined: Jun 03, 2011
Posts: 15
Now I have edited that code to this:



It does not have a sharp sound anymore, but it still makes the noise that I started out with. Just for a shorter time period.

How could I stop the noise from occurring completely?
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 159

How about:

Braden Steffaniak
Greenhorn

Joined: Jun 03, 2011
Posts: 15
That loop just controls whether to loop or not. The nested loops are the ones that play the audio.
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 159

Yes, but each time through the loop you call line.start() and line.close().
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Quit audio before application exits.
 
Similar Threads
Problem stopping a Player in JMF
Problem stopping audio in using sun.audio package
Using Java to access Sound Card
Application/Applet the plays audio files.
Java Sound API problems