Hi,

Try out this code base:

*package com.audio.recorder;*
*
*
*import java.io.File;*
*
*
*import android.app.Activity;*
*import android.media.MediaPlayer;*
*import android.media.MediaRecorder;*
*import android.os.Bundle;*
*import android.util.Log;*
*import android.view.View;*
*import android.view.View.OnClickListener;*
*import android.widget.Button;*
*
*
*/***
* * *
* * @author lisudza*
* **
* */*
*
*
*public class AudioRecorder extends Activity {*
*
*
* **private MediaPlayer mediaPlayer;*
* **private MediaRecorder mediaRecorder;*
* **private static final String OUTPUT_FILE = "/sdcard/recordoutput.3gpp";*
* **private String APP_NAME = "AudioRecorder";*
*
*
* **/** Called when the activity is first created. */*
* *...@override*
* **public void onCreate(Bundle savedInstanceState) {*
* **super.onCreate(savedInstanceState);*
* **setContentView(R.layout.main);*
* **Button startBtn = (Button) findViewById(R.id.beginRecording);*
* **Button endBtn = (Button) findViewById(R.id.stopRecording);*
* **Button playRecordingBtn = (Button) findViewById(R.id.playRecording);*
* **Button stpPlayingRecordingBtn = (Button) findViewById(R.id.stopPlaying);
*
*
*
* **startBtn.setOnClickListener(new OnClickListener() {*
*
*
* **public void onClick(View v) {*
* **// TODO Auto-generated method stub*
* **try {*
* **Log.d(APP_NAME, "Start recording......");*
* **beginRecording();*
* **} catch (Exception ex) {*
* **Log.e(APP_NAME, "Failed to start recording ", ex);*
* **}*
* **}*
* **});*
*
*
* **endBtn.setOnClickListener(new OnClickListener() {*
*
*
* **public void onClick(View v) {*
* **try {*
* **stopRecording();*
* **} catch (Exception ex) {*
* **Log.e(APP_NAME, "Oh Oh Failed to stop recording. ", ex);*
* **}*
* **}*
* **});*
*
*
* **stpPlayingRecordingBtn.setOnClickListener(new OnClickListener() {*
*
*
* **public void onClick(View v) {*
* **try {*
* **stopPlayingRecording();*
* **Log.d(APP_NAME, "Just stopped Recording...");*
* **} catch (Exception ex) {*
* **Log.e(APP_NAME, "Not Good could not stop playing the recorded sound. ",
ex);*
* **}*
* **}*
* **});*
*
*
* **playRecordingBtn.setOnClickListener(new OnClickListener() {*
*
*
* **public void onClick(View v) {*
* **// TODO Auto-generated method stub*
* **try {*
* **playRecording();*
* **} catch (Exception ex) {*
* **Log.e(APP_NAME, "Application could play the recording...",*
* **ex);*
* **}*
* **}*
* **});*
*
*
* **stpPlayingRecordingBtn.setOnClickListener(new OnClickListener() {*
*
*
* **public void onClick(View v) {*
* **try {*
* **playRecording();*
* **}catch (Exception ex ){*
* **Log.e(APP_NAME, "Failed to Start Playing the record...", ex);*
* **}*
* **}*
* **});*
* **}*
*
*
* **/***
* ** * Method <b>beginRecording</b> prepares and starts the audio capturing.
*
* ** * *
* ** * @throws Exception*
* ** */*
* **private void beginRecording() throws Exception {*
* **killMediaRecorder();*
*
*
* **File outFile = new File(OUTPUT_FILE);*
*
*
* **if (outFile.exists()) {*
* **Log.d(APP_NAME, "The File exists. Deleted");*
* **outFile.delete();*
* **}*
*
*
* **mediaRecorder = new MediaRecorder();*
* **mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);*
* **mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);*
* **mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);*
* **mediaRecorder.setOutputFile(OUTPUT_FILE);*
* **mediaRecorder.prepare();*
* **mediaRecorder.start();*
* **}*
*
*
* **/***
* ** * Method <b>killMediaRecorder</b> - checks for an active MediaRecorder*
* ** * object and kills it.*
* ** * *
* ** */*
*
*
* **private void killMediaRecorder() {*
* **if (mediaRecorder != null) {*
* **mediaRecorder.release();*
* **}*
* **}*
*
*
* **private void stopRecording() {*
* **if (mediaRecorder != null) {*
* **mediaRecorder.stop();*
* **}*
* **}*
*
*
* **/***
* ** * Method <b> killMediaPlayer</b> kills and releases the media player.*
* ** */*
* **private void killMediaplayer() {*
* **if (mediaPlayer != null) {*
* **try {*
* **mediaPlayer.release();*
* **} catch (Exception ex) {*
* **Log.e(APP_NAME, "Failed to kill the media player.", ex);*
* **}*
* **}*
* **}*
*
*
* **private void playRecording() throws Exception {*
* **killMediaplayer();*
* **mediaPlayer = new MediaPlayer();*
* **mediaPlayer.setDataSource(OUTPUT_FILE);*
* **mediaPlayer.prepare();*
* **mediaPlayer.start();*
* **}*
*
*
* **private void stopPlayingRecording() throws Exception {*
* **if (mediaPlayer != null) {*
* **mediaPlayer.stop();*
* **}*
* **}*
*
*
* *...@override*
* **protected void onDestroy() {*
* **super.onDestroy();*
* **killMediaplayer();*
* **killMediaRecorder();*
* **Log.d(APP_NAME, "Finished clearing all held resources...");*
* **}*
*}*
*
*

Here is the layout file:

*<?xml version="1.0" encoding="utf-8"?>*
*<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"*
*    android:orientation="vertical"*
*    android:layout_width="fill_parent"*
*    android:layout_height="fill_parent">*
* **<Button*
* **android:id="@+id/beginRecording"  *
*    ** **android:layout_width="fill_parent" *
*    ** **android:layout_height="wrap_content" *
*    ** **android:text="Begin Recording"/>*
*    <Button *
*    ** **android:id="@+id/stopRecording"*
*    ** **android:layout_width="fill_parent"*
*    ** **android:layout_height="wrap_content"*
*    ** **android:text="Stop Recording"/>*
*    <Button*
*    ** **android:id="@+id/playRecording"*
*    ** **android:layout_width="fill_parent"*
*    ** **android:layout_height="wrap_content"*
*    ** **android:text="Play Recording"/>*
*    <Button*
*    ** **android:id="@+id/stopPlaying"*
*    ** **android:layout_width="fill_parent"*
*    ** **android:layout_height="wrap_content"*
*    ** **android:text="Stop Playing Recording"/>** *
*    ** *
*</LinearLayout>*


Hope it helps. Its running on my G1 perfectly.


On Fri, Apr 16, 2010 at 3:46 AM, hshong <aan...@gmail.com> wrote:

> hi.
>
> below link contains a example code of audio capture
> http://developer.android.com/guide/topics/media/index.html#capture
>
> my problem is..
> "MediaStore.MediaColumns" class don't have TIMESTAMP constant.
> see also,
> http://developer.android.com/reference/android/provider/MediaStore.MediaColumns.html
>
> i'd like to audio capture.
> any suggestion?
>
> thanks.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Beginners" group.
>
> NEW! Try asking and tagging your question on Stack Overflow at
> http://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-beginners?hl=en
>



-- 
Regards,

Kenn Lisudza
T: 254722720215
Twitter: @kennlisudza

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to