我需要知道我应该用什么来控制我使用jLayer创建的MP3播放器的音量?我可以使用哪些API或方法来控制mp3文件的音量?
答案 0 :(得分:0)
public class VolumeSlider{
// to get the aydiosystem gain control
public void setGain(float ctrl)
{
try {
Mixer.Info[] infos = AudioSystem.getMixerInfo();
for (Mixer.Info info: infos)
{
Mixer mixer = AudioSystem.getMixer(info);
if (mixer.isLineSupported(Port.Info.SPEAKER))
{
Port port = (Port)mixer.getLine(Port.Info.SPEAKER);
port.open();
if (port.isControlSupported(FloatControl.Type.VOLUME))
{
FloatControl volume = (FloatControl)port.getControl(FloatControl.Type.VOLUME);
volume.setValue(ctrl);
}
port.close();
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Erro\n"+e);
}
}