Skip to content
Browse files

Push to talk with sample playback working into a file.

  • Loading branch information...
1 parent 0c7f6f4 commit 57324e6ca1abb50fbb3d3ee8fe056a4a834e67c9 @cpatrick cpatrick committed Sep 1, 2011
Showing with 17 additions and 10 deletions.
  1. +1 −0 AndroidManifest.xml
  2. +16 −10 src/org/miloss/TalkActivity.java
View
1 AndroidManifest.xml
@@ -3,6 +3,7 @@
package="org.miloss"
android:versionCode="1"
android:versionName="1.0">
+<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
View
26 src/org/miloss/TalkActivity.java
@@ -23,6 +23,7 @@
import android.app.Activity;
import android.os.Bundle;
+import android.os.Environment;
import android.provider.MediaStore.Audio;
import android.util.Log;
import android.view.MotionEvent;
@@ -48,8 +49,10 @@
/**
* Media player and recorder
*/
- AudioRecord mRecorder;
+ MediaRecorder mRecorder;
ByteBuffer mAudioBuffer;
+ String mFileName;
+ String mFile;
public static final String TAG = "TalkActivity";
@@ -104,23 +107,23 @@ public void onClick(View v) {
};
private void startRecording() throws IllegalStateException, IOException {
- MediaRecorder recorder = new MediaRecorder();
- recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
- recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
- recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
- FileOutputStream file = new FileOutputStream("/sdcard/output.sound");
- recorder.setOutputFile(file.getFD());
- recorder.prepare();
- recorder.start();
+ mRecorder = new MediaRecorder();
+ mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
+ mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
+ mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
+ mRecorder.setOutputFile(mFileName);
+ mRecorder.prepare();
+ mRecorder.start();
}
private void stopRecording() throws IllegalArgumentException, IllegalStateException, IOException {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
+
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
- mediaPlayer.setDataSource("/sdcard/output.sound");
+ mediaPlayer.setDataSource(mFileName);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();
}
@@ -143,6 +146,9 @@ public void setupEventListeners()
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
+ mFileName += "/audiorecordtest.3gp";
+
setContentView(R.layout.main);
setupUIReferences();
setupEventListeners();

0 comments on commit 57324e6

Please sign in to comment.
Something went wrong with that request. Please try again.