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.
In AudioEffect, there are 3 types of error occurs.
this occurs for your case
.Operation failed due to bad parameter value. It causes IllegalArgumentException and gives the error "AudioEffect: bad parameter value"
Operation failed because it was requested in wrong state. It causes UnsupportedOperationException and gives the error "AudioEffect: invalid parameter operation"
It occurs in runtime. It gives the error "AudioEffect: set/get parameter error"
Ans: After finishing process of an equalizer, if it doesn't called the release()
method, the wrong state happens. So make the equalizer object equal to null after releasing it.
If you use api level 25, then change it. This error occurs in this level mostly. So, if possible, change it.
Sometimes instantiation of a new AudioEffect is not allowed by native libraries. because too many objects are already exists there. It also causes wrong state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With