javax.sound.sampled cannot change volume of clip

public void play(float volume) {
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(file));
DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
((FloatControl) AudioSystem.getMixer(null).getControl(FloatControl.Type.VOLUME)).setValue(volume);
clip.open(stream);
clip.start();
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
}
}
public void play(float volume) {
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(file));
DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
((FloatControl) AudioSystem.getMixer(null).getControl(FloatControl.Type.VOLUME)).setValue(volume);
clip.open(stream);
clip.start();
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
}
}
The method above should play a .wav file at the specified volume (file is a byte[] loaded from the .wav). However, Java tells me that it's an unsupported control type. I've tried everything and none of it works. Am I just missing something obvious? This is what the oracle site told me to do. I have a windows 11 surface pro 7, and Minecraft can change audio volume, so it's not my device. Help?
20 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @The Typhothanian! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
The Typhothanian
The TyphothanianOP10mo ago
anyone? ugh
JavaBot
JavaBot10mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
dan1st
dan1st10mo ago
Stack Overflow
Set volume of Java Clip
Is there any way to set the respective volume of a Clip in Java? I have this method: public static void play(Clip clip) { if (Settings.getSettings().isVolumeOn()) { FloatControl volum...
dan1st
dan1st10mo ago
wth FloatControl.Type.MASTER_GAIN
The Typhothanian
The TyphothanianOP10mo ago
lemme check Same error All control types are unsupported
dan1st
dan1st10mo ago
Does it work with other types of audio? i.e. non-WAV what's the exact exception?
The Typhothanian
The TyphothanianOP10mo ago
sorry
The Typhothanian
The TyphothanianOP10mo ago
or small Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Unsupported control type: Volume at java.desktop/com.sun.media.sound.AbstractLine.getControl(AbstractLine.java:149) at net.typho.utils.resources.AudioFile.play(AudioFile.java:42) at net.typho.utils.uwt.UButton$1.mousePressed(UButton.java:42) Getting a bunch of "stream of unsupported format"s. Which formats are supported, do you know?
dan1st
dan1st10mo ago
and you also get unsupported control type MASTER_GAIN? ?
The Typhothanian
The TyphothanianOP10mo ago
Yeah, all controls are unsupported. Also, I was doing .wav, but with .aiff and .mp3 got UnsupportedAudioFileExceptions
dan1st
dan1st10mo ago
yeah Java doesn't support mp3 by default
The Typhothanian
The TyphothanianOP10mo ago
I tried a bunch of stuff on the web but all of it's from 2011 so no luck
dan1st
dan1st10mo ago
Stack Overflow
AbstractLine Unsupported control type: Master Gain Java
I am having an error when using Clip.getControl() as per:- import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; imp...
dan1st
dan1st10mo ago
lol first open then change the controls
The Typhothanian
The TyphothanianOP10mo ago
i am so absolutely stupid omg
dan1st
dan1st10mo ago
Does it work?
The Typhothanian
The TyphothanianOP10mo ago
had to move after the start but yeah
JavaBot
JavaBot10mo ago
Post Closed
This post has been closed by <@801145088830210129>.
Want results from more Discord servers?
Add your server