4

I'm creating mediaPlayer with EQ, when I set the EQ bands it works fine. I have code that lists all presets, on change I want to set the preset to EQ, but I'm getting bad parameter value.

This is what I have in my log:

09-29 14:29:24.810: W/System.err(27829): java.lang.IllegalArgumentException: AudioEffect: bad parameter value
09-29 14:29:24.835: W/System.err(27829):    at android.media.audiofx.AudioEffect.checkStatus(AudioEffect.java:1259)    
09-29 14:29:24.835: W/System.err(27829):    at android.media.audiofx.Equalizer.usePreset(Equalizer.java:342)

getNumberOfPresets() returns 12 and preset to set for this example is 2 (but it happens for all values 0-11)

If I use setBandLevel() before usePreset() it's not throwing an exception, but i'm not sure if this is the right way to do it. Edit: setBandLevel has nothing to do with the exception. It just pops out randomly, 80% of the tries.

Update: I noticed that this is happening on Samsung S3 devices (for now) only. Works fine on Asus TF101.

Any help is appreciated.

Here is the code:

mEqualizer = new Equalizer(0, mMediaPlayer.getAudioSessionId());
mEqualizer.setEnabled(true);
mEqualizer.usePreset((short)mEQPresetPos);
cucko
  • 1,436
  • 11
  • 25
  • Show us the code how you are calling the Equalizer. – RvdK Sep 30 '13 at 14:40
  • I updated the question with code. – cucko Sep 30 '13 at 14:43
  • I don't understand how this code sometimes works and sometimes throws exception, for same mEQPresetPos value. – cucko Sep 30 '13 at 14:46
  • What is the value of mEQPresetPos ? – RvdK Sep 30 '13 at 15:01
  • Have you tried calling setEnabled as last? Seems more logical to first setup the equalizer and then activate it. – RvdK Sep 30 '13 at 15:02
  • `getNumberOfPresets() = 12` mEQPresetPos in this example is 2 (but it happens for all values 0-11). it's not > 11 for sure. again, for same value sometimes works sometimes not. – cucko Sep 30 '13 at 15:03
  • nothing changed by moving setEnabled as last, I even removed that line. – cucko Sep 30 '13 at 15:07
  • I've set breakpoint to check mEqualizer properties. As i can see, they are the same both times (when works and when it's not) – cucko Sep 30 '13 at 15:11
  • another strange thing. this is happening on Samsung Galaxy S3 i9300 (reported by now, and tested by me). on asus tf101 works fine. – cucko Sep 30 '13 at 16:06
  • A bit more code wouldn't hurt. Specifically, where/how `mEQPresetPos` gets initialized/assigned. – Geobits Sep 30 '13 at 17:10
  • mEQPresetPos is set on spinner.setOnItemSelectedListener, where spinner adapter is filled with getPresetName(0 to (getNumberOfPresets() -1)) the value is not the problem, again, mEQPresetPos in this example is 2 (but it happens for all values 0-11). it's not > 11 for sure. again, for same value sometimes works sometimes not. so, if i set it as const=0, the problem will still be there (on i9300 device). – cucko Sep 30 '13 at 17:16
  • ok. how i solved the problem. i know it's not a good solution, but here it is: i have a loop (with max repeat counter = 10), it resets the mEqualizer and call usePreset until not throws an error. so far so good. – cucko Sep 30 '13 at 17:45
  • Hey @cucko did your solution work out? What exception did you catch? I'm having the same issue with various devices reported by users. :/ – Jona Apr 12 '14 at 15:36
  • no solution yet. i'm still using the code from my prev comment. – cucko Apr 12 '14 at 17:00
  • I am getting the same error java.lang.UnsupportedOperationException: AudioEffect: invalid parameter operation on Android 7.0 and its working fine on 6.0 – AkhilGite Nov 28 '16 at 09:05
  • provide the entire source code so we can debug :P –  Feb 12 '17 at 11:11

1 Answers1

3

It may be due to two reasons.

your device may be not supporting Equalizer. But as you said you get a list of Preset. It means it is supporting.

Now the problem may be that you have two instance of Equalizer. you must release Equalizer.

or try

add equalizer.setEnabled(false);

before creating another one.

shehzy
  • 2,215
  • 3
  • 25
  • 45