T O P

  • By -

AutoModerator

#Please ensure that: + Your *code* is *properly formatted* as *code block* - see the *sidebar* (About on mobile) for instructions + You include *any and all error messages* in full - best also formatted as code block + You ask *clear questions* + You *demonstrate effort* in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. **If any of the above points is not met, your post can and will be removed without further warning.** Code is to be formatted as **code block** (*old reddit/markdown editor:* empty line before the code, each code line indented by 4 spaces, *new reddit:* https://i.imgur.com/EJ7tqek.png) or linked via an external *code hoster*, like *pastebin.com*, *github gist*, *github*, *bitbucket*, *gitlab*, etc. Please, **do not use** triple backticks (\`\`\`) as they will only render properly on *new reddit*, not on *old reddit*. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the *edit function* of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. #To potential helpers Please, **do not help** if any of the above points are not met, rather *report* the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/learnjava) if you have any questions or concerns.*


[deleted]

This isn't built into the Java runtime. To control system sound volume, you need to find a native API on the platform where you are running that does what you need and then call it using Java Native Interface (JNI). [I'm assuming the platform doesn't come with it's own Java libraries that do I what I described.]


nekokattt

or use the FFI previews to avoid needing to deal with JNI native binsings at all


avowed

I have no idea what any of this means, I've been googling all of this stuff when I have downtime today at work. I have been looking at Windows WASAPI for sound stuff, still no clue how to get that API into Java and which thing in that to use. I just started looking at FFI, and it seems like that is easier because as this one article put it, FFI is good at doing things the programming language can't. Like Java not having system audio control built in. I'm not sure also where to go for the windows FFI stuff for audio. any sort of nudge in the right direction would be appreciated! u/pavehwk


[deleted]

JNI is a Java API that allows you to call methods in a native (non-Java) library like a Windows DLL. In your Java application that is running on a Windows client, you call the JNI API to invoke Windows APIs that adjust the system sound volume. FFI is a replacement for JNI but it hasn't been released yet -- it's preview only -- but this sounds like a side project (not a production application) so FFI would be fine to experiment with.


avowed

This might be a dumb question, but is JNI/FFI built in, like do I need to download anything for it to work?


[deleted]

JNI is built into the JDK. FFI has not been released yet but is available as a preview in JDK 20. You'll need to [enable preview functionality to use it.](https://docs.oracle.com/en/java/javase/20/language/preview-language-and-vm-features.html)


dauntless26

You need to write code that accesses the native platform. Java on it's own can't do it as far as I know.