编程语言
首页 > 编程语言> > 用Java打开/关闭计算机音量?

用Java打开/关闭计算机音量?

作者:互联网

我想用一个命令上下调整计算机的主音量(100%/ 0%).
我看到我可以使用FloatControl,但我不确定如何使用它.

解决方法:

看看using JavaSound to control the master volume.

从链接:

Mixer.Info [] mixers = AudioSystem.getMixerInfo();  
System.out.println("There are " + mixers.length + " mixer info objects");  
for (Mixer.Info mixerInfo : mixers)  
{  
    System.out.println("Mixer name: " + mixerInfo.getName());  
    Mixer mixer = AudioSystem.getMixer(mixerInfo);  
    Line.Info [] lineInfos = mixer.getTargetLineInfo(); // target, not source  
    for (Line.Info lineInfo : lineInfos)  
    {  
        System.out.println("  Line.Info: " + lineInfo);  
        Line line = null;  
        boolean opened = true;  
        try  
        {  
            line = mixer.getLine(lineInfo);  
            opened = line.isOpen() || line instanceof Clip;  
            if (!opened)  
            {  
                line.open();  
            }  
            FloatControl volCtrl = (FloatControl)line.getControl(FloatControl.Type.VOLUME);  
            System.out.println("    volCtrl.getValue() = " + volCtrl.getValue());  
        }  
        catch (LineUnavailableException e)  
        {  
            e.printStackTrace();  
        }  
        catch (IllegalArgumentException iaEx)  
        {  
            System.out.println("    " + iaEx);  
        }  
        finally  
        {  
            if (line != null && !opened)  
            {  
                line.close();  
            }  
        }  
    }  
} 

标签:java,audio,javasound
来源: https://codeday.me/bug/20190529/1180034.html