1. Are you ready for the Galaxy S20? Here is everything we know so far!

Visualizer initCheck failed -3 (ERROR_NO_INIT)

Discussion in 'Android Development' started by apech, Feb 15, 2016.

  1. apech

    apech Lurker
    Thread Starter

    I'm trying to create a simple audio visualizer app but keep getting this error while trying to instantiate the Visualizer class. The documentation only states that this error is due to bad object initialization. Does anyone have more information about what causes this error?

    I've already made sure to have the RECORD_AUDIO and MODIFY_AUDIO_SETTINGS permissions granted before I instantiate the Visualizer. The pseudocode below shows how I'm instantiating it:
    Code (Text):
    1.  
    2. Visualizer mVizualizer;
    3.  
    4. protected void onCreate() {
    5.  
    6.     if (permissionsGranted) {
    7.         initVisualizer();
    8.     } else {
    9.         requestPermissions();
    10.     }
    11. }
    12.  
    13. private void initVisualizer() {
    14.  
    15.     mVisualizer = new Visualizer(0); // audioSession = 0 to access output audio mix
    16.  
    17.     // setup visualizer...
    18.  
    19. }
    20.  
    It's my understanding that using the output audio mix requires the MODIFY_AUDIO_SETTINGS permission in addition to RECORD_AUDIO, but I already have both of these so I don't know what I'm missing.
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Deleted User

    Deleted User Guest

    According to the reference API documentation for Visualizer, ERROR_NO_INIT is due to 'Operation failed due to bad object initialization.' Not much help.
    I presume you got that error in your Logcat view? Does it give you any more error messages? Do you get a stack trace?
    The other thing you could try is setting a breakpoint in the code, stepping through to establish where the error is coming from, and stepping into the Visualizer code to see what's going on.
     
  3. Deleted User

    Deleted User Guest

    This error code is returned by the method


    int setDataCaptureListener
    ()

    Can you please show the part of your code which is calling this method?
     
  4. apech

    apech Lurker
    Thread Starter

    I've set a breakpoint and stepped through the code and it's definitely not the setDataCaptureListener function. If I step into
    Code (Text):
    1. mVisualizer = new Visualizer(0);
    then I can see the native_setup function (line 9) returning the -3 error code. I can't step into this function though to see what's going on.

    Code (Text):
    1.  
    2. public Visualizer(int audioSession)
    3. throws UnsupportedOperationException, RuntimeException {
    4.     int[] id = new int[1];
    5.  
    6.     synchronized (mStateLock) {
    7.         mState = STATE_UNINITIALIZED;
    8.         // native initialization
    9.         int result = native_setup(new WeakReference<Visualizer>(this), audioSession, id,
    10.                 ActivityThread.currentOpPackageName());
    11.         if (result != SUCCESS && result != ALREADY_EXISTS) {
    12.             Log.e(TAG, "Error code "+result+" when initializing Visualizer.");
    13.             switch (result) {
    14.             case ERROR_INVALID_OPERATION:
    15.                 throw (new UnsupportedOperationException("Effect library not loaded"));
    16.             default:
    17.                 throw (new RuntimeException("Cannot initialize Visualizer engine, error: "
    18.                         +result));
    19.             }
    20.         }
    21.         mId = id[0];
    22.         if (native_getEnabled()) {
    23.             mState = STATE_ENABLED;
    24.         } else {
    25.             mState = STATE_INITIALIZED;
    26.         }
    27.     }
    28. }
    29.  
    Here is the stack trace from the exception:

    02-16 09:11:44.615 16933-16933/com.alexpech.visualisertest E/AudioEffect: set(): AudioFlinger could not create effect, status: -1
    02-16 09:11:44.615 16933-16933/com.alexpech.visualisertest E/visualizers-JNI: Visualizer initCheck failed -3
    02-16 09:11:44.615 16933-16933/com.alexpech.visualisertest E/Visualizer-JAVA: Error code -3 when initializing Visualizer.
    02-16 09:11:44.617 16933-16933/com.alexpech.visualisertest E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.alexpech.visualisertest, PID: 16933
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alexpech.visualisertest/com.alexpech.visualisertest.VisualiserActivity}: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2484)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
    at android.app.ActivityThread.access$900(ActivityThread.java:150)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:168)
    at android.app.ActivityThread.main(ActivityThread.java:5845)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
    Caused by: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3
    at android.media.audiofx.Visualizer.<init>(Visualizer.java:218)
    at com.alexpech.visualisertest.VisualiserActivity.setupVisualiserFxAndUI(VisualiserActivity.java:129)
    at com.alexpech.visualisertest.VisualiserActivity.initAudio(VisualiserActivity.java:123)
    at com.alexpech.visualisertest.VisualiserActivity.onCreate(VisualiserActivity.java:65)
    at android.app.Activity.performCreate(Activity.java:6248)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
    at android.app.ActivityThread.access$900(ActivityThread.java:150)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:168)
    at android.app.ActivityThread.main(ActivityThread.java:5845)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
     
  5. apech

    apech Lurker
    Thread Starter

    One more thing I've discovered - passing a non-zero argument to the Visualizer constructor doesn't cause an error. However it doesn't give me the output audio mix in this case.
     
  6. apech

    apech Lurker
    Thread Starter

    The Visualizer class is very poorly documented but it seems that accessing the output audio using audioSession = 0 might be deprecated. It's not mentioned in the Visualizer class but it is in the AudioEffect class. Is anyone able to verify that this is the case?

    Also, any suggestions for workarounds would be much appreciated! If I can't get the Visualizer class to behave I think I'll have to look into added a MediaPlayer and accessing the device's music through the app.
     
Loading...
Similar Threads - Visualizer initCheck failed
  1. Papamalo
    Replies:
    5
    Views:
    327
  2. Eroot
    Replies:
    14
    Views:
    803
  3. Hannibal 99
    Replies:
    4
    Views:
    624
  4. minimum nebula
    Replies:
    0
    Views:
    1,324
  5. Mojo88
    Replies:
    10
    Views:
    2,883
  6. The_Chief
    Replies:
    11
    Views:
    2,513
  7. kblanco
    Replies:
    7
    Views:
    1,797
  8. App Update
    Replies:
    0
    Views:
    1,314
  9. floxp
    Replies:
    3
    Views:
    2,521
  10. gstq54
    Replies:
    1
    Views:
    621

Share This Page

Loading...