Android Cannot initialize Visualizer engine, error: -4

I have an error:

public class VisualizerCapture extends Activity implements Visualizer.OnDataCaptureListener { private Visualizer mVisualizer = new Visualizer(0); // error is here!!! @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setupVisualizer(); } 

This is an abandoned error:

  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{bla bla}: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -4 

My manifest:

  <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> <uses-permission android:name="android.permission.INTERNET"/> 

Setting method:

 private void setupVisualizer() { Visualizer.setEnabled(false); Visualizer.setCaptureSize(1); //test Visualizer.setDataCaptureListener(this,250,false,true); //Visualizer.setScalingMode(visualizer.SCALING_MODE_AS_PLAYED); Visualizer.setEnabled(true); Log.v("ABS","setupVisualizer" + Visualizer.getEnabled()); //log } 

Why did I get this error? Looks like I got all the permissions?

Be patient, I'm new to development. How can i fix this?

+2
android
source share
3 answers

After reading the documentation:

 public Visualizer (int audioSession) Added in API level 9 Class constructor. Parameters audioSession system wide unique audio session identifier. If audioSession is not 0, the visualizer will be attached to the MediaPlayer or AudioTrack in the same audio session. Otherwise, the Visualizer will apply to the output mix. 

Are you sure you want 0?

Update

Looking towards the error:

 public static final int ERROR_BAD_VALUE Added in API level 9 Operation failed due to bad parameter value. Constant Value: -4 (0xfffffffc) 

This is the error you are getting, you probably have something bad in your Visualizer configuration, double check the contents in your setupVisualizer.

+1
source share

You cannot get Visualizer to work on all platforms. This is one of the least tested objects in Android and should not be released by imho. You absolutely need to catch exceptions wherever you touch it.

Visualizer is most likely one of the most complex and undocumented classes you have ever used. It has DSP and FFT weirdness combined with covert error handling.

Eg. You must also create an equalizer instance when using Visualizer to bypass volume controls.

You should never instantiate objects in the class declaration section. This makes it difficult to detect exceptions, and also makes it difficult to inject dependency.

You must create objects in the constructor or init method of the class so that you can catch exceptions and also support mocks testing for dependency injection.

0
source share

Add permission in manifest file

 <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> 

If added, then check

Goto AppInfo for this application; Go to permissions make sure all permissions granted by this application have been granted.

0
source share

All Articles