I have a start button that initiates audio recording, and a stop button that ends the process.
This is the java code of the start button:
startbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//My code
}
});
This is the java code for the stop button:
stopbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//My code
}
});
This is their respective XML layout if needed:
<Button
android:id="@+id/btnRecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="120dp"
android:layout_marginBottom="100dp"
android:text="Start Recording" />
<Button
android:id="@+id/btnStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="100dp"
android:layout_marginBottom="40dp"
android:text="Stop Recording" />
So far i use "setEnabled(True)" or "false" to manage the app. Instead i need to merge these states in a single button so it can be "START/STOP" for a more simplistic UI... There are more buttons but i will fix them on my own hopefully, after learning the how to. Cheers!
PS: I typed "//My code" instead of the actual code in order to save space. I can provide my code if needed.
UPDATE: My logcat:
2019-02-27 13:17:29.634 8550-8550/com.android.greg.garec E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.greg.garec, PID: 8550
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaRecorder.stop()' on a null object reference
at com.android.greg.garec.MainActivity$1.onClick(MainActivity.java:96)
at android.view.View.performClick(View.java:6897)
at android.widget.TextView.performClick(TextView.java:12693)
at android.view.View$PerformClick.run(View.java:26101)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)