簡體   English   中英

Java:Master Gain不支持異常

[英]Java: Master Gain not supported exception

在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中它是否有效。

謝謝,Martijn。

在嘗試使用控件之前,你可以嘗試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 );
}

它看起來有所不同,具體取決於JRE版本。

我遇到了類似的問題,當我檢查dataLine.getControls()時,我在Oracle JDK 1.7上獲得了一個“MASTER_GAIN”控件,在OpenJDK 1.6上獲得了一個“Volume”控件。 更糟糕的是......“音量”的線性值從0到65536,而MASTER_GAIN似乎有一個分貝設置。

代碼一次,到處運行:-(

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM