GautamChibde/android-audio-visualizer

java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3

Surabhi3 opened this issue · 3 comments

public void setPlayer(int audioSessionId) {

    visualizer = new Visualizer(audioSessionId);
    visualizer.setEnabled(false);
    visualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);


    visualizer.setDataCaptureListener(new Visualizer.OnDataCaptureListener() {
        @Override
        public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
                                          int samplingRate) {
            BaseVisualizer.this.bytes = bytes;
            invalidate();
        }

        @Override
        public void onFftDataCapture(Visualizer visualizer, byte[] bytes,
                                     int samplingRate) {
        }
    }, Visualizer.getMaxCaptureRate() / 2, true, false);

    visualizer.setEnabled(true);
}

If you are using android 5 or above, you need to request for audio_record permission manually, not just only put it on manifest. Google for code snippet to request permission.

I am requesting the permission and i had allowed app for it. But it is crashing

refer #4