Setting volume with java
Good day!
I'm developing an application that plays a MIDI. It plays fine, but I often get quasi-bug reports: 'there is no sound playd'. The answer is always, to enter into volume controller and turn the synthesizer sound on (make it not muted).
The question is - how to change it automatically - by software? Till now I can only change the master volume and I couldn't really anywhere find how to change only for 'wave' 'SW synthesizer' etc...
I'm generally looking for platform indenpendent solutions (开发者_Go百科pure java), however solution only for Windows (all sorts of windows) are also welcomed ;) Thank you ahead!
Edit: Well, looking at the answers, I see, I should specify my question better. I append image. The control selected with green is what I can already do (i.e. as Cliff linked) however I need something for controls in red (the most important in my case is the 3rd from the left - synthesizer volume). Image is taken from win XP, but other operating systems (linux also) have similar controls. Java has to have such possibility.
I've looked in Ubuntu, Fedora, and Windows and the only commonalities across these OS's is the master volume and the alert (or "beep" on Windows) volume. This leads me to believe that there is no platform-independent way of doing this, meaning no standard Java way.
That being said, there is most likely APIs (probably different) for all of these OS's which allow you to control these finer-grain settings. If so, it will almost definitely require separate Java libraries for interacting with these APIs on each platform.
Sorry I can't point you in the right direction but I am hoping to at least help you eliminate the possibility of having a standardized way of doing this function. Good luck!
Try peeking at what happens in the background when you adjust the wave/synthesizer levels using the tool in the screenshot using sysinternal's Process Monitor, and then have your java code do the same native system/dll call.
Are you working with some sort of interface or using the system's default Mixer
? And what level of control are you talking about? Unfortunately I'm learning this API as well but my first thought is that each of those would be a different line, right? Have you tried getting all of the system lines and using the MASTER_GAIN
on each of the lines? Like the person above me said I'm sure there are API's for this but if I were going to do it in my own code for educational purposes or something that is where I would start. Speaking of API's there is a Control API that manipulates the audio data itself but as far as I know doesn't affect the hardware's volume control.
精彩评论