如何为均衡器布局?
How to make a layout for the equalizer?
这是我用来设置 5 波段均衡器 的代码,但我想要一个支持数字的 Layout设备支持的均衡器频段。
现在我硬编码均衡器频段的大小,因为我不确定如何创建布局 用于均衡器频带的非常量值。
这是我想使用的代码:
equalizer.getNumberOfBands(); //it tells you the number of equalizer in device.
但是如果设备支持 +10 个均衡器频段,我如何才能在屏幕上显示这些 频段?
创建均衡器的代码
private void setupEqualizer(){
mEqualizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
final short lowerEqualizerBandLevel = mEqualizer.getBandLevelRange()[0];
final short upperEqualizerBandLevel = mEqualizer.getBandLevelRange()[1];
for (short i = 0; i < 5; i++){
final short equalizerBandIndex = i;
int freq_range = mEqualizer.getCenterFreq(equalizerBandIndex);
verticalSeekbar[i].setMax(upperEqualizerBandLevel - lowerEqualizerBandLevel);
verticalSeekbar[i].setProgress(mEqualizer.getBandLevel(equalizerBandIndex));
verticalSeekbar[i].setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
mEqualizer.setBandLevel(equalizerBandIndex, (short) (progress + lowerEqualizerBandLevel ));
slider_value[equalizerBandIndex].setText(String.valueOf((progress + lowerEqualizerBandLevel) / 100 + " dB"));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
slider_labels[i].setText(formatBandLabel(freq_range));
float scale2 = getResources().getDisplayMetrics().density;
int dpAsPixels2 = (int) (8*scale2 + 0.5f);
}
setupEqSpinner();
}
You need to use Vertical SeekBar as told by Nilesh
equalizer.getNumberOfBands() // it tells the number of equalizer ..
创建一个 LinearLayout(Horizontal)
并在 for 循环中添加 Vertical Seekbar (numberOfBands
)..
这是我用来设置 5 波段均衡器 的代码,但我想要一个支持数字的 Layout设备支持的均衡器频段。
现在我硬编码均衡器频段的大小,因为我不确定如何创建布局 用于均衡器频带的非常量值。
这是我想使用的代码:
equalizer.getNumberOfBands(); //it tells you the number of equalizer in device.
但是如果设备支持 +10 个均衡器频段,我如何才能在屏幕上显示这些 频段?
创建均衡器的代码
private void setupEqualizer(){
mEqualizer = new Equalizer(0, mediaPlayer.getAudioSessionId());
final short lowerEqualizerBandLevel = mEqualizer.getBandLevelRange()[0];
final short upperEqualizerBandLevel = mEqualizer.getBandLevelRange()[1];
for (short i = 0; i < 5; i++){
final short equalizerBandIndex = i;
int freq_range = mEqualizer.getCenterFreq(equalizerBandIndex);
verticalSeekbar[i].setMax(upperEqualizerBandLevel - lowerEqualizerBandLevel);
verticalSeekbar[i].setProgress(mEqualizer.getBandLevel(equalizerBandIndex));
verticalSeekbar[i].setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
mEqualizer.setBandLevel(equalizerBandIndex, (short) (progress + lowerEqualizerBandLevel ));
slider_value[equalizerBandIndex].setText(String.valueOf((progress + lowerEqualizerBandLevel) / 100 + " dB"));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
slider_labels[i].setText(formatBandLabel(freq_range));
float scale2 = getResources().getDisplayMetrics().density;
int dpAsPixels2 = (int) (8*scale2 + 0.5f);
}
setupEqSpinner();
}
You need to use Vertical SeekBar as told by Nilesh
equalizer.getNumberOfBands() // it tells the number of equalizer ..
创建一个 LinearLayout(Horizontal)
并在 for 循环中添加 Vertical Seekbar (numberOfBands
)..