by Lakshumaiah » Thu Jan 27, 2011 12:27 pm
package com.AudioRecording;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class AudioRecording extends Activity
{
public static String path=null;
public static MediaRecorder recoder=null;
public static MediaPlayer player=null;
Button start=null;
Button stop=null;
Button Play=null;
public void setPath(String modPath)
{
AudioRecording.path=modPath;
}
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.main);
this.setPath(“/sdcard/myoutputfile.3gp”);
start=(Button)findViewById(R.id.btnRecord);
Play=(Button)findViewById(R.id.startPlayerBtn);
Play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
player=new MediaPlayer();
try {
player.setDataSource(“/sdcard/myoutputfile.3gp”);
player.prepare();
player.start();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
System.out.println(“Testing File\n”);
recoder=new MediaRecorder();
recoder.setAudioSource(MediaRecorder.AudioSource.MIC);
recoder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recoder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recoder.setOutputFile(AudioRecording.path);
try
{
recoder.prepare();
recoder.start();
}catch(IOException e)
{}
}
});
stop=(Button)findViewById(R.id.stopPlayerBtn);
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
stopPlayingRecording();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
private void stopPlayingRecording() throws Exception {
if(recoder!=null)
{
recoder.stop();
}
}
}
This is the code i have written for recording audio through micro phone. I am able to record voice but i am unable to play back it, please help me to play
steps i have taken to execute this code is:
i created sdcard img and i stored the output_file int. But it is not playing