I'm new to android programming and audio visualization. I want to create a simple audio visualizer using MediaPlayer
and Visualizer
classes. My problem is, I don't know what wave form data
really is. Must I use it to visualize audio?
I'm using the code below. It's problem is, it will only visualize audio for the first 10-12 seconds of the file; after that, I'm unable to capture more data! Where did I go wrong?
public void attachVisualizer()
{
Visualizer vis = new Visualizer(mPlayer.getAudioSessionId());
vis.setCaptureSize(Visualizer.getCaptureSizeRange()[0]);
vis.setDataCaptureListener(new Visualizer.OnDataCaptureListener() {
public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) {
int sum = 0;
for(int i = 0; i < bytes.length; i++) {
sum += bytes[i];
}
if(sum > 8000) {
// Do something which uses mPlayer.getCurrentPosition() in mathematics
}
}
public void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate) {}
}, Visualizer.getMaxCaptureRate() , true, false);
vis.setEnabled(true);
}
EDIT
And another question in my mind is, how do I record the length of time contained in a given audio segment?