how do i change volume of Clip that is playing in loop?

大城市里の小女人 提交于 2020-06-08 06:18:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!