This is my code i use to setup a 5 band Equalizer, but i would like to have a Layout which supports the number of equalizer bands supported by the device.
For now i have hardcoded the size of Equalizer bands because i'm not sure how to create a Layout for a non constant value of equalizer bands.
This is the code i would like to use:
equalizer.getNumberOfBands(); //it tells you the number of equalizer in device.
But what if a device supports +10 equalizer bands, how can i fit those bands on the screen?
Code for creating Equalizer
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 ..
Create a LinearLayout(Horizontal)
and add Vertical Seekbar to it in a for loop (numberOfBands
)..