Android Visualizer class throwing runtime exception

匿名 (未验证) 提交于 2019-12-03 08:41:19

问题:

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());     } 

回答1:

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



回答2:

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 .



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!