问题
I am wrecking my brain on how to change the volume of a Clip that is already playing in loop mode. The code I currently have is:
Clip c = currentSound.getClip();
FloatControl gainControl =
(FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(-10.0f);
currentSound.loop(loopCount);
Is my assumption that once the loop starts, the volume cannot be changed, true?
回答1:
Is my assumption that once the loop starts, the volume cannot be changed, true?
No. A Clip
volume can be changed at any time, if it can be changed at all.
回答2:
As an alternative, if you would like real-time control over Clip
volumes, you can make use of AudioCue. It is a small library, and was modeled as closely as I could on the Clip
class. The volume control is guaranteed as it is done in Java rather than relying on a FloatControl
that relies on the presence of capabilities offered by the OS and hardware, and changes are spread out on a per frame basis rather than changing only on a per-buffer boundaries.
来源:https://stackoverflow.com/questions/23590046/how-do-i-change-volume-of-clip-that-is-playing-in-loop