Im looping all my presets and want to use them after that.
Now the first getBandLevel
method Im calling is returning me an acceptable value but all the other method calls in the loop returns me 0. Where could I be wrong ?
Here is my code with the loop:
m_equalizer.usePreset((short)position);
short numberFrequencyBands = .m_equalizer.getNumberOfBands();
final short lowerEqualizerBandLevel = m_equalizer.getBandLevelRange()[0];
for(short x=0;x<numberFrequencyBands;x++)
{
SeekBar seekbar= (SeekBar)findViewById((short)x);
seekbar.setProgress(m_equalizer.getBandLevel((short) x) - lowerEqualizerBandLevel ); //Here is getBandLevel returning me 0 after x is 1
}
Edit: I also checked if other apps are also giving 0 and they dont.They have right settings
Code:
public void equalizeSound()
{
ArrayList<String> equalizePresetNames = new ArrayList<String>();
ArrayAdapter<String> equalizerPresetSpinnerAdapter = new ArrayAdapter<String>(this,R.layout.custom_spinner_item_small,equalizePresetNames);
equalizerPresetSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner equalizerPresetSpinner = (Spinner)findViewById(R.id.spinner_presets_eq);
for(short i=0;i< m_equalizer.getNumberOfPresets();++i)
{
equalizePresetNames.add(m_equalizer.getPresetName(i));
}
equalizerPresetSpinner.setAdapter(equalizerPresetSpinnerAdapter);
equalizerPresetSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
m_equalizer.usePreset((short)position);
short numberFrequencyBands = m_equalizer.getNumberOfBands();
final short lowerEqualizerBandLevel = m_equalizer.getBandLevelRange()[0];
for(short x=0;x<numberFrequencyBands;x++)
{
SeekBar seekbar= (SeekBar)findViewById((short)x);
seekbar.setProgress(m_equalizer.getBandLevel((short) x) - lowerEqualizerBandLevel );
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
The SeekBar.OnSeekBarChangeListener
of your SeekBar
s is changing the values of the presets.
Set the OnSeekBarChangeListener
inside the for loop, removing the previous one:
SeekBar seekbar= (SeekBar)findViewById((short)x);
seekbar.setOnSeekBarChangeListener(null);
seekbar.setProgress(m_equalizer.getBandLevel((short) x) - lowerEqualizerBandLevel );
seekbar.setOnSeekBarChangeListener(yourListenerHere);