11

I am using AndroidFX Visualizer class in my demo app to read FFT but when i try to create object of that class its throwing Runtime exception (java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -1). Player class is my custom class for playback control and using same Player class i have implemented equalizer class and that's working fine. Do i need to add any permission in manifest file?

Player mediaPlayer = Player.GetInstance();
    mediaPlayer.LoadFile("song.mp3");
    mediaPlayer.Play();
    try{
    visual = new Visualizer(mediaPlayer.GetAudioSessionID()); // this line causing Exception 
    visual.setEnabled(true);
    visual.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
    }
    catch(Exception ex)
    {
        Log.e("Visual Ex", ex.getMessage());
    }
Raj
  • 3,890
  • 7
  • 52
  • 80

2 Answers2

32

That was due to my foolish mistake, that feature requires <uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission> permission. thanks

Raj
  • 3,890
  • 7
  • 52
  • 80
13

I know this is a very late answer but I also struggled with this problem and I want to share my experiences.

First, as the answer above mentioned, the permissions

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

and, if audio source 0 is used (Visualizer(0); //system mix),

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

are needed. After adding the permissions to my app and installing the (new compiled) app again, my app still crashed. I found out, that the device has to be restarted, to use the Visualizer without any exception (for whatever reason). So if you develop an app and get this exception, a restart could be required after adding the permissions to the app .

Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
  • 1
    I've been looking for an answer, and restarting my device fixed the issue! Thank you @Fruchtzwerg – Chris Rohit Brendan May 20 '17 at 11:47
  • 1
    Thank you Fruchtzwerg! It was restarting my device that fixed the issue as well. In NO WAY should this be required, and I believe it is a bug with android, specifically around the `MODIFY_AUDIO_SETTINGS` permission. – Big Money Mar 29 '19 at 18:12