title: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -4
body: <p>I am getting below error when running app on API  16.</p>
  
  <pre><code> java.lang.RuntimeException: Unable to start activity ComponentInfo{}: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -4
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                        at android.app.ActivityThread.access$600(ActivityThread.java:130)
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                        at android.os.Handler.dispatchMessage(Handler.java:99)
                        at android.os.Looper.loop(Looper.java:137)
                        at android.app.ActivityThread.main(ActivityThread.java:4745)
                        at java.lang.reflect.Method.invokeNative(Native Method)
                        at java.lang.reflect.Method.invoke(Method.java:511)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                        at dalvik.system.NativeStart.main(Native Method)
                     Caused by: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -4
                        at android.media.audiofx.Visualizer.&lt;init&gt;(Visualizer.java:199)
                        at xyz.activity.AudioPreviewActivity.setupVisualizerFxAndUI(AudioPreviewActivity.java:83)
                        at xyz.activity.AudioPreviewActivity.initAudio(AudioPreviewActivity.java:60)
                        at xyz.activity.AudioPreviewActivity.onCreate(AudioPreviewActivity.java:40)
                        at android.app.Activity.performCreate(Activity.java:5008)
                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
                        at android.app.ActivityThread.access$600(ActivityThread.java:130) 
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
                        at android.os.Handler.dispatchMessage(Handler.java:99) 
                        at android.os.Looper.loop(Looper.java:137) 
                        at android.app.ActivityThread.main(ActivityThread.java:4745) 
                        at java.lang.reflect.Method.invokeNative(Native Method) 
                        at java.lang.reflect.Method.invoke(Method.java:511) 
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                        at dalvik.system.NativeStart.main(Native Method)   
  </code></pre>
  
  <p>Error line-</p>
  
  <pre><code>mVisualizer = new Visualizer(mMediaPlayer.getAudioSessionId());
  </code></pre>
  
  <p>Code</p>
  
  <pre><code>private void setupVisualizerFxAndUI() {
  
      mMediaPlayer = MediaPlayer.create(this, Uri.parse(filePath));
      mMediaPlayer
              .setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                  public void onCompletion(MediaPlayer mediaPlayer) {
                      mVisualizer.setEnabled(false);
                  }
              });
  
      mMediaPlayer.start();
      mMediaPlayer.setLooping(true);
      mVisualizer = new Visualizer(mMediaPlayer.getAudioSessionId());
      mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
      mVisualizer.setDataCaptureListener(
                      new Visualizer.OnDataCaptureListener() {
                          public void onWaveFormDataCapture(Visualizer visualizer,
                                                            byte[] bytes, int samplingRate) {
                              mVisualizerView.updateVisualizer(bytes);
                          }
  
                          public void onFftDataCapture(Visualizer visualizer,
                                                       byte[] bytes, int samplingRate) {
                          }
                      }, Visualizer.getMaxCaptureRate() / 2, true, false);
          }
  </code></pre>
  
  <p>I already have added below permissions in manifest-</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.RECORD_AUDIO"/&gt;
  &lt;uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/&gt;
  </code></pre>