我无法制作可以同时录制和收听的应用。我已经创建了一个能够在此刻录制和播放的录音机,但如果有人可以就如何开始使用android studio提出建议以便我可以让应用程序同时录制和收听,我将非常感激。
stop.setEnabled(false);
play.setEnabled(false);
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myrec.3gp";
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
}
public void start(View v) {
try {
myAudioRecorder.prepare();
myAudioRecorder.start();
}catch (IllegalStateException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
start.setEnabled(false);
stop.setEnabled(true);
Toast.makeText(this,"Recording started",Toast.LENGTH_SHORT).show();
}
public void stop(View v) {
myAudioRecorder.stop();
myAudioRecorder.release();
myAudioRecorder=null;
stop.setEnabled(false);
play.setEnabled(true);
Toast.makeText(this,"Audio successfully recorded",Toast.LENGTH_SHORT).show();
}
public void play(View v) throws IOException {
MediaPlayer m=new MediaPlayer();
m.setDataSource(outputFile);
m.prepare();
m.start();
Toast.makeText(this,"Playing audio", Toast.LENGTH_SHORT).show();
}
}