3

VisualizerView works with a file via linking but It's not the same for MediaRecorder . MediaRecorder getMaxAmplitude() function returns only the highest value but I need to get a byte array for each frequency . Is there any way to do this ?

dodo
  • 141
  • 8

2 Answers2

2

Finally I have fond a solution and it wasn't that hard to do it . There is a method which captures the fft data real-time . Here is my exapmle ,

    recordingThread = new VisualizerAudioRecordingThread(fileName, new VisualizerAudioRecordingHandler() {
        //pass file name where to store the recorded audio
        @Override
        public void onFftDataCapture(final byte[] bytes) {
            onActivity.runOnUiThread(new Runnable() {
                public void run() {
                    if (Dialog.mVisualizerView != null) {
                        Dialog.mVisualizerView.updateVisualizerFFT(bytes); //update VisualizerView with new audio portion
                    }
                }
            });
        }

        @Override
        public void onRecordSuccess() {
        }

        @Override
        public void onRecordingError() {}

        @Override
        public void onRecordSaveError() {}
    });
    recordingThread.start();
    }

Here is the full example and where I get this information , https://github.com/steelkiwi/AndroidRecording

dodo
  • 141
  • 8
1

VisualizerView is linking to a MediaPlayer, not to a MediaRecorder.

You don't have access through the MediaRecorder to what happens inside the AudioEncoder in real time, only receive any errors that may occur...

Maybe if you save the audio to a file and then process it can solve your problem?

http://developer.android.com/guide/topics/media/audio-capture.html

prc
  • 860
  • 7
  • 16
  • I am also doing that , there are two options one of them plays a recorded sound and one of them is recording and playing a recorded sound works fine . Now, I want to add a visualizer to the view while recording it . – dodo Aug 27 '15 at 08:58
  • As per Visualizer class description on Android Developers documentation: "The Visualizer class enables application to retrieve part of the currently playing audio for visualization purpose." Notice the "playing audio" part. It is not available while recording as far as I know... – prc Aug 27 '15 at 09:09