I'm in a fraternity in college and in this fraternity we have stairs. Every now and again somebody falls down those stairs. We generally play music from the computer behind the bar (usually from the internet or itunes). I have a usb button, and would like to write a program that temporarily mutes the background music and plays a clip from the song "Wiiiipe-ouuut" when I press the button after someone falls down the stairs. How could I do this with the sound... anyone have any ideas?
-
Possible duplicate of [Can Java Sound be used to control the system volume?](http://stackoverflow.com/questions/14301618/can-java-sound-be-used-to-control-the-system-volume) – Andrew Thompson Feb 09 '13 at 03:03
-
+1 for the comedy problem description – mikera Feb 09 '13 at 03:15
-
Just use a browser to open that page: http://www.sadtrombone.com/ – Cyrille Ka Feb 09 '13 at 03:46
-
@Andrew - I don't think this is an "exact" duplicate of your link. This poster doesn't wish to turn down the system volume, because you still want to be able to play and hear the Java sound effect! Rather, the gist of the question is whether the volumes of other software be muted temporarily from Java. However, THAT question may have been asked and answered before, I don't know. – Phil Freihofner Feb 10 '13 at 03:17
1 Answers
It is pretty easy to make a Java app that exposes little more than a button that plays a given sound cue, or even a set of buttons for different cues.
You would presumably leave the application running, waiting for the right time to press the button, in order to get a near-instantaneous response. I'd use the Swing library to make the button and javax.sound.sampled.Clip to hold the sound in memory and play it on command. However, there are maybe even easier audio objects to do this, since you really don't need to do anything but play the cue at full volume. Also, JavaFX is starting to be used for gui buttons.
I don't know how to turn down the iTunes or Browser volume from Java. This is NOT to say it can't be done. If someone else can say how, definitely select their answer! I just haven't tried to do that yet.
But, maybe it is not so hard to manually turn up and down the volume of iTunes or the Browser if you practice a few times. Turning its volume up or down has the benefit of not being as disruptive as stopping and restarting the music application. So, turn down the volume in the app (not the main computer volume!), mouse over to the Java button app and click it, wait for the sound to end and turn the volume of the music app back up. Not ideal, but it would do the job of producing the desired sounds.
Another idea, maybe instead of controlling the music apps, there is a way to route the output of the apps through Java before playing them. In that case, a single button push could be written to handle the entire sequence. I'd look into the TargetDataLine as the main tool used to handle the inputting of the sound stream, but don't know how you'd ID the appropriate mixer lines or ports. It's likely something that has to be customized to your setup and OS and sound card or sound system.
Fun idea! Another language might also work for this, e.g., a separate small browser window with HTML5 and a button for launching a sound effect.

- 7,645
- 1
- 20
- 41