I followed the steps here to play audio in Java. From the docs:
Your program might need a specific kind of mixer, or you might want to display a list of all the available mixers so that the user can select one. In either case, you need to learn what kinds of mixers are installed. AudioSystem provides the following method:
static Mixer.Info[] getMixerInfo()
However when I call the method I am getting an empty array. I am developing using JDK 21 on WSL. I am developing a "plain" console Java application without any GUI libraries. Things I have checked:
- I am able to play sound using
ffplay
- I have
libjsound.so
under$JAVA_HOME/lib
Does the use of this API require one to develop a rich Java application like JavaFX etc.? I don't see anything like that mentioned in the docs.
I followed the steps here to play audio in Java. From the docs:
Your program might need a specific kind of mixer, or you might want to display a list of all the available mixers so that the user can select one. In either case, you need to learn what kinds of mixers are installed. AudioSystem provides the following method:
static Mixer.Info[] getMixerInfo()
However when I call the method I am getting an empty array. I am developing using JDK 21 on WSL. I am developing a "plain" console Java application without any GUI libraries. Things I have checked:
- I am able to play sound using
ffplay
- I have
libjsound.so
under$JAVA_HOME/lib
Does the use of this API require one to develop a rich Java application like JavaFX etc.? I don't see anything like that mentioned in the docs.
Share Improve this question edited Jan 31 at 17:22 greg-449 111k235 gold badges109 silver badges159 bronze badges asked Jan 31 at 17:18 morpheusmorpheus 20.4k29 gold badges108 silver badges186 bronze badges 4 |1 Answer
Reset to default 0I think you can count on letting Java select the default mixer, unless you have some special need (which you haven't mentioned).
The code examples in the wiki for the Javasound tag have examples and information for how to use a Clip
or SourceDataLine
.
The supporting code package, javax.sound.sampled is part of Core Java, (no additional libraries needed), but this package does require the inclusion of the module java.desktop.
main
method (macOS) – greg-449 Commented Jan 31 at 17:32ldd libjsound.so
, it says it depends onlibasound.so.2
. Does your WSL have that? – VGR Commented Jan 31 at 18:05