Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Visualizer class throwing runtime exception

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());
    }
like image 471
Raj Avatar asked Aug 07 '11 08:08

Raj


2 Answers

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

like image 89
Raj Avatar answered Nov 10 '22 01:11

Raj


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 .

like image 22
Fruchtzwerg Avatar answered Nov 10 '22 03:11

Fruchtzwerg