5

I have tried using various AudioEffect classes on AudioRecord/MediaPlayer and every time i am getting the same error as soon as i call a new object of the AudioEffect class. I am getting the following error -

04-28 18:31:06.571: **E/AudioEffect(6688): set(): AudioFlinger could not create effect, status: -22**
04-28 18:31:06.571: **E/AudioEffects-JNI(6688): AudioEffect initCheck failed -4**
04-28 18:31:06.571: **E/AudioEffect-JAVA(6688): Error code -4 when initializing AudioEffect.**

For example I had written the following code where I am creating an object of MediaPlayer class and sending an output file which contains my mp3 recording to setDataSource function. Then according the the android api documentation http://developer.android.com/reference/android/media/audiofx/LoudnessEnhancer.html I am supposed to send audio session id to the constructor of LoudnessEnhancer object. Also i have set the Target Gain at 100 and setEnabled true.

MediaPlayer m = new MediaPlayer();
m.setDataSource(outputFile);

int sessionID=m.getAudioSessionId();
AudioEffect effect=new LoudnessEnhancer(sessionID);
((LoudnessEnhancer) effect).setTargetGain(100);
((LoudnessEnhancer) effect).setEnabled(true);

m.prepare();
m.start();

Note : whenever I debug the code and as soon as it hits the constructor of LoudnessEnhancer I get a message saying Source not attached. So I checked the windows->preferences->java->installed jre and it shows the correct path. However in my Project->BuildPath->configure Build Path->Libraries When I checked the Native Library Location, the path shows none. I don't know which path to include here if at all it is required

Is it possible that my project is unable to find certain sources necessary to instantiate the constructor of the AudioEffect class ?

Kindly give suggestions..

shalvi_pandita
  • 143
  • 1
  • 9
  • set the effect after the audio file has been prepared , and get the session id there (in the onPrepared listener) – Koma Yip Sep 13 '15 at 05:12

0 Answers0