mercredi 21 janvier 2015

Android Visualizer

So I am trying to use the audio visualizer to play along with the audio. But i am getting an error. The listview for the songs is coming out fine,but after that when I click on a song the app crahses. Heres the logcat:



01-22 07:58:42.710 8140-8140/app.my.com.wave E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{http://ift.tt/1CfPCrL}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2118)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2143)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:4952)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at app.my.com.wave.V.onCreate(V.java:28)
at android.app.Activity.performCreate(Activity.java:5188)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at


Heres the V class for the visualizer:



package app.my.com.wave;

import android.content.Intent;
import android.media.MediaPlayer;
import android.media.audiofx.Visualizer;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import java.io.IOException;


public class V extends ActionBarActivity {
private MediaPlayer mPlayer;
private byte[] mBytes;
private byte[] mFFTBytes;
private Visualizer mVisualizer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_v);

Intent i = getIntent();
String path = i.getStringExtra("path");

try {
mPlayer.setDataSource(path);
mPlayer.prepare();

} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

mPlayer.start();
mPlayer.setLooping(false);
mVisualizer = new Visualizer(mPlayer.getAudioSessionId());
mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);

Visualizer.OnDataCaptureListener captureListener = new Visualizer.OnDataCaptureListener() {
@Override
public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
int samplingRate) {
System.out.println("onWaveFormDataCapture");
}

@Override
public void onFftDataCapture(Visualizer visualizer, byte[] bytes,
int samplingRate) {
System.out.println("onFftDataCapture");
}
};

mVisualizer.setDataCaptureListener(captureListener,
Visualizer.getMaxCaptureRate() / 2, true, false);

mVisualizer.setEnabled(true);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mVisualizer.setEnabled(false);
}
});
}}


So the app crashes once I press a song. Please help me out and thanks in advance.


Aucun commentaire:

Enregistrer un commentaire