meysam jahedi
دوشنبه 04 اسفند 1393, 22:52 عصر
سلام
نمیدونم چرا از دستورات زیر برای AudioRecorder استفاده میکنم ، اما وقتی روی play میزنم هیچ اتفاقی نمیفته
public class record extends Activity{
private MediaRecorder myAudioRecorder;
private String outputFile = null;
private Button start,stop,play;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.record);
start = (Button)findViewById(R.id.btn_start);
stop = (Button)findViewById(R.id.btn_stop);
play = (Button)findViewById(R.id.btn_play);
stop.setEnabled(false);
play.setEnabled(false);
outputFile = Environment.getExternalStorageDirectory().
getAbsolutePath() + "/myrecording.3gp";;
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.Audio Source.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.Outp utFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.Outp utFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
}
public void start(View view){
try {
myAudioRecorder.prepare();
myAudioRecorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
start.setEnabled(false);
stop.setEnabled(true);
Toast.makeText(getApplicationContext(), "Recording started", Toast.LENGTH_LONG).show();
}
public void stop(View view){
myAudioRecorder.stop();
myAudioRecorder.release();
myAudioRecorder = null;
stop.setEnabled(false);
play.setEnabled(true);
Toast.makeText(getApplicationContext(), "Audio recorded successfully",
Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void play(View view) throws IllegalArgumentException,
SecurityException, IllegalStateException, IOException{
MediaPlayer m = new MediaPlayer();
m.setDataSource(outputFile);
m.prepare();
m.start();
Toast.makeText(getApplicationContext(), "Playing audio", Toast.LENGTH_LONG).show();
}
}
نمیدونم چرا از دستورات زیر برای AudioRecorder استفاده میکنم ، اما وقتی روی play میزنم هیچ اتفاقی نمیفته
public class record extends Activity{
private MediaRecorder myAudioRecorder;
private String outputFile = null;
private Button start,stop,play;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.record);
start = (Button)findViewById(R.id.btn_start);
stop = (Button)findViewById(R.id.btn_stop);
play = (Button)findViewById(R.id.btn_play);
stop.setEnabled(false);
play.setEnabled(false);
outputFile = Environment.getExternalStorageDirectory().
getAbsolutePath() + "/myrecording.3gp";;
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.Audio Source.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.Outp utFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.Outp utFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
}
public void start(View view){
try {
myAudioRecorder.prepare();
myAudioRecorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
start.setEnabled(false);
stop.setEnabled(true);
Toast.makeText(getApplicationContext(), "Recording started", Toast.LENGTH_LONG).show();
}
public void stop(View view){
myAudioRecorder.stop();
myAudioRecorder.release();
myAudioRecorder = null;
stop.setEnabled(false);
play.setEnabled(true);
Toast.makeText(getApplicationContext(), "Audio recorded successfully",
Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void play(View view) throws IllegalArgumentException,
SecurityException, IllegalStateException, IOException{
MediaPlayer m = new MediaPlayer();
m.setDataSource(outputFile);
m.prepare();
m.start();
Toast.makeText(getApplicationContext(), "Playing audio", Toast.LENGTH_LONG).show();
}
}