AudioSystem.getLine() throws an exception when using Eclipse, but the program runs fine on the command line

Viewed 24

I have a sound project I built on Windows several years ago. It uses the AudioSystem class that is built into Java to play sound. I am now on Fedora, and getting this program to run has been a nightmare.

In the terminal:

I can run my test program like this: java --module-path $PATH_TO_FX --add-modules "javafx.swing,javafx.controls" test/Main.java. It has it's own issue where it hangs at a SourceDataLine.write() call, but runs fine to that point.

The Java version output is

openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment (Red_Hat-17.0.4.0.8-1.fc36) (build 17.0.4+8)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.4.0.8-1.fc36) (build 17.0.4+8, mixed mode, sharing)

In Eclipse:

I added the following to VM arguments in the run configuration: --module-path "${PATH_TO_FX}" --add-modules "javafx.swing,javafx.controls". I set the JRE system library to JavaSE-17.

The program starts successfully, but then another issue pops up.

Exception in thread "main" java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian is supported.
    at java.desktop/javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:425)
    at java.desktop/javax.sound.sampled.AudioSystem.getSourceDataLine(AudioSystem.java:534)
    at audioLines.MonoAudioLine.<init>(MonoAudioLine.java:29)
    at test.Main.testSineWave(Main.java:197)
    at test.Main.main(Main.java:76)

It turns out that AudioSystem.getMixerInfo(); returns an empty array.

How do I fix this dumpster fire?

0 Answers
Related