I'm getting an UnsupportedOperationException error on an equalizer on this line of code. bassBoost.setStrength((short) bassBoostPos);
Here's the code
equalizer = new Equalizer(0, 0);
if (equalizer != null) {
equalizer.setEnabled (isEqualizer);
numBands = equalizer.getNumberOfBands();
short r[] = equalizer.getBandLevelRange();
minLevel = r[0];
maxLevel = r[1];
bassBoost = new BassBoost (0, 0);
if(bassBoost != null) {
bassBoost.setEnabled(bassBoostPos > 0 ? true : false);
bassBoost.setStrength((short) bassBoostPos);
}
Here's the exception
java.lang.UnsupportedOperationException: AudioEffect: invalid parameter
operation
at android.media.audiofx.AudioEffect.checkStatus(AudioEffect.java:1271)
at android.media.audiofx.BassBoost.setStrength(BassBoost.java:127)
How do I fix this so that the application doesn't crash. I mean how can I check to see if the device support this operation, if it doesn't support, I would just skip this line. Thanks.
UnsupportedOperationException
is typically thrown by a concrete implementation of an interface or abstract class if it decides not to implement a certain operation. A client doesn't know if the concrete implementation supports the operation until it calls it. Otherwise it would have to have knowledge about all existing (and future) concrete implementations. – CohlaAudioEffect
classes is that sometimes they work perfectly well and sometimes they don't and instead throw the exception even on the same device. – PavebassBoost.setEnabled(bassBoostPos > 0 ? true : false);
was returning -5 when another system equalizer was enabled else 0 . same for Equalizer set enabled() . a temporary solution if system has equalizer then call it else use yours. – Electrodeposit