2

I am testing equalizer in my Android Version 7.1.1 but it shows a Runtime Exception but It's perfectly working on below version 7.0.

When I try to initialize equalizer :

private static UUID EQUALIZER_UUID;
mp = MediaPlayer.create(this, R.raw.a);
mp.start();
if(hasEqualizer()) {
   equalizer = new Equalizer(0, mp.getAudioSessionId());
   equalizer = equalizerUtil.getEqualizer(mp);
   Log.d("No. of Presets",String.valueOf(equalizer.getNumberOfPresets()));
}

public static boolean hasEqualizer() {
    for (AudioEffect.Descriptor effect : AudioEffect.queryEffects()) {
        if (EQUALIZER_UUID.equals(effect.type)) {
            return true;
        }
    }
    return false;
}

It Shows Error :

java.lang.RuntimeException: Cannot initialize effect engine for type: 0bed4300-ddd6-11db-8f34-0002a5d5c51b Error: -3
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2678)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
          at android.app.ActivityThread.-wrap12(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:154)
          at android.app.ActivityThread.main(ActivityThread.java:6165)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: java.lang.RuntimeException: Cannot initialize effect engine for type: 0bed4300-ddd6-11db-8f34-0002a5d5c51b Error: -3

I had tried various solutions available on - java.lang.RuntimeException: Cannot initialize effect engine for type: 0bed4300-ddd6-11db-8f34-0002a5d5c51b Error: -3, but Nothing works

Can someone have any ideas?

Rohit Gurjar
  • 437
  • 4
  • 12
  • For anyone having this problem in 2023 on Pixel 7Pro, this may be related to https://issuetracker.google.com/issues/261579107 – algrid Jun 05 '23 at 13:08

1 Answers1

1

It looks like it might be an issue with getAudioSessionId() if a session ID isn't available yet. See this response on the thread linked below:

That means it hasn't been set yet. You can use player.setAudioDebugListener to listen for the ID being set (the ID will be passed via onAudioSessionId when it is).

https://github.com/google/ExoPlayer/issues/2357

Robert Nekic
  • 3,087
  • 3
  • 24
  • 36
  • 1
    //Debug Mode : int i = mp.getAudioSessionId(); i:27721 – Rohit Gurjar Feb 06 '18 at 18:45
  • I tried a quick test and I see the same error on a Nexus 5X with 7.1.2. The solution suggested by this link does indeed fix the problem. If I add an AudioRendererEventListener via mediaPlayer.setAudioDebugListener and initialize the Equalizer when onAudioSessionId fires, the error does not occur and the equalizer looks normal – Robert Nekic Feb 06 '18 at 19:02
  • Whatever you are suggesting me is in terms of ExoPlayer but I am using MediaPlayer and there is no method like setAudioDebugListener in it – Rohit Gurjar Feb 06 '18 at 19:10
  • Good point. I assumed MediaPlayer would have the same option, but it does not. It's probably the same underlying issue but it needs a different solution for the standard MediaPlayer. Hmm... – Robert Nekic Feb 06 '18 at 19:19
  • I'm not seeing the error on the same device when I use the standard MediaPlayer. When are you constructing the Equalizer? Can you add more of the relevant code to to the question to show where in the MediaPlayer lifespan/usage the Equalizer is constructed? – Robert Nekic Feb 06 '18 at 19:27
  • So, have you know any other solution or any method that checks equalizer is supported on any device or not? – Rohit Gurjar Feb 06 '18 at 19:27
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/164643/discussion-between-rohit-gurjar-and-robert-nekic). – Rohit Gurjar Feb 06 '18 at 19:34