Java:Master Gain 不支持异常

标签 java linux audio volume

在 Linux 中此代码不起作用:我添加了两行

// Added two lines.
DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat );
SourceDataLine dataLine = (SourceDataLine) AudioSystem.getLine( info );
// Adjust the volume on the output line.
if( dataLine.isControlSupported( FloatControl.Type.MASTER_GAIN)) {
    // If inside this if, the Master_Gain must be supported. Yes?
    FloatControl volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN);
    // This line throws an exception. "Master_Gain not supported"
    volume.setValue( 100.0F );
}

这正常吗?我必须做什么才能解决这个问题?
在Windows中它可以工作。

谢谢马丁。

最佳答案

您能否在尝试使用控件之前尝试open() 该行。像这样的事情:

// Added two lines.
DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat );
SourceDataLine dataLine = (SourceDataLine) AudioSystem.getLine( info );
dataLine.open();
// Adjust the volume on the output line.
if( dataLine.isControlSupported( FloatControl.Type.MASTER_GAIN)) {
    // If inside this if, the Master_Gain must be supported. Yes?
    FloatControl volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN);
    // This line throws an exception. "Master_Gain not supported"
    volume.setValue( 100.0F );
}

关于Java:Master Gain 不支持异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1827607/

相关文章:

java - 如何在Dialog android中设置videoView

linux - 如何通过 shell 脚本在远程服务器上连接和运行 shell 脚本

android - Flex Mobile:无法在Android设备中播放AAC音频

iphone - AVPlayerItem 暂停直播 URL?

flash - 使对象对Flash中的声音使用react

java - Android WallpaperManager 方法 "soft-bricking"用户的手机并导致设备无响应

更新数据时,Javafx 条形图 X 轴无法正确缩放

java - 如何确定我是否已在 super.equals 调用链中到达对象?

linux - 使用heroku调度程序调度websolr重新索引

c - getopt() 解析模式不起作用