This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Hello. I'm attempting to write a class that will load and play MIDIs as either sound effects or background music for a game. Since the music was overpowering the sound effects, I needed to find a way to adjust the volume. I thought it would be a simple thing to do so, but after searching the Internet for hours I'm still at a loss. I've attempted to isolate the problem with the following bare-bones code, which is drawn partly from Killer Game Programming in Java:
Everything compiles fine, and the background music midi file plays when I run the program. My attempts to change the volume, however, do nothing. Immediately before and after the call to controlChange, all channels display as being set to 127. I did discover that if I put in a Thread.sleep(1000) right after sequence.start(), the volume change is successful, but the channel values still do not read what I attempted to set them to. Half of them still read 127, and the other half read arbitrary values (which stay the same on subsequent runs of the program). Moreover, it will not be very helpful for my sound effects to have to wait a second into their playtime for their volume to be changed.
I just started teaching myself Java a couple months ago, and I am completely stumped as to how I can change a value, immediately print that value, and not see the change reflected. Any insight at all would be greatly appreciated!