public static MediaPlayer mp=null;
public static void playGeneric(int name, final ImageButton button,final ImageButton pervious,Context context) {
button.setEnabled(
use runOnUiThread for mediaRecorder prepare.
private boolean prepareMediaRecorder() {
mediaRecorder = new MediaRecorder();
runOnUiThread(new Runnable() {
@Override
public void run() {
mediaRecorder.reset();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setOutputFile(filePath);
try {
mediaRecorder.prepare();
} catch (IOException e) {
mediaRecorder = null;
return;
}
mediaRecorder.start();
recording = true;
}
});
return true;
}