androidexceptionequalizer

Caused by java.lang.UnsupportedOperationException in the equalizer


I am trying to fix a bug in my app but the problem is I am not able to fix the bug as i am not able to recreate the crash but I am able to get the log and i am not able to identify what is the issue i referred the question related to UnsupportedOperationException but till now no success any guide of hint will be helpful

Log1

Fatal Exception: java.lang.RuntimeException
Unable to create service com.musicplayer.music.audioplayer.PlayerService: 
java.lang.RuntimeException: AudioEffect: set/get parameter error
android.app.ActivityThread.handleCreateService (ActivityThread.java:2801)
android.app.ActivityThread.access$1800 (ActivityThread.java:155)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1400)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:135)
android.app.ActivityThread.main (ActivityThread.java:5343)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run 
(ZygoteInit.java:905)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:700)

logcat 2

    Caused by java.lang.RuntimeException
 AudioEffect: set/get parameter error
android.media.audiofx.AudioEffect.<init> (AudioEffect.java:407)
android.media.audiofx.Virtualizer.<init> (Virtualizer.java:120)
com.musicplayer.music.audioplayer.equalizermerge.model.EqualizerApi.init 
(EqualizerApi.java:23)
com.musicplayer.music.audioplayer.PlayerService.onCreate 
(PlayerService.java:400)
android.app.ActivityThread.handleCreateService (ActivityThread.java:3141)
android.app.ActivityThread.access$1800 (ActivityThread.java:178)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1640)
android.os.Handler.dispatchMessage (Handler.java:111)
android.os.Looper.loop (Looper.java:214)
android.app.ActivityThread.main (ActivityThread.java:6102)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run 
(ZygoteInit.java:1028)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:823)

As suggested i have added the complete log cat from the io.fabric EqualizerApi code


Solution

  • I found a version of the source code (https://android.googlesource.com/platform/frameworks/base/+/5bb8f80/media/java/android/media/audiofx/AudioEffect.java), though the line numbers don't match your stacktrace.

    It appears that an UnsupportedOperationException is thrown as a result of a problem when initializing the native code implementation of the audio effect engine. In the code I am looking at, the exception message says "Effect library not loaded". I am guessing it is caused by one of the following:


    Update - The updated stacktrace and error message indicate that the problem is happening when you create the Virtualizer. The message implies that it is due to a bad parameter.

    Looking through the code for the AudioEffect and Virtualizer classes, it appears that the Virtualizer initialzer is attempting to retrieve a parameter from the native API to test if the Virtualizer "strength" parameter is supported. It appears like the API is saying that it doesn't even understand the parameter that is supposed to say whether the strength parameter is supported(!)

    The comments in the Virtualizer class near where the parameter numbers are specified say this:

    // These constants must be synchronized with those in 
    // frameworks/base/include/media/EffectVirtualizerApi.h
    

    Based on the behavior I deduced, it seems that is not true. In other words, I think ... somehow ... you are using a version of the Java API that doesn't match the version of the native API.

    Alternatively, this might be happening because Virtualizer support is broken on those devices.

    I would suggest the following work-arounds:

    1. Try to catch the runtime exception in your init method, and treat the Virtualizer functionality as disabled on the device.

    2. If you know what the offending devices are, code your init method to not even try to configure a Virtualizer on those devices.

    3. Don't support those devices at all. (Are they old? Are they running old / poorly maintained builds of Android? Are they even worth supporting?)

    It is also possible that the problem is related one of these Q&As: