Hi,

Did you set the below permission in AndroidManifest.xml

<uses-permission android:name="android.permission.RECORD_AUDIO" />

Regards,
Manoj

On Dec 10, 9:30 am, Lei <[EMAIL PROTECTED]> wrote:
> Hi all,
> I want to record the audio from the micphone. But I failed.
> I reference the document. And the link 
> is:http://code.google.com/android/toolbox/apis/media.html
>
> I got the file. Its size is always 1666B. I played it but hear
> nothing.
>
> Thanks in advance.
> Regards,
> Lei
>
> The code is :
>
> public class MediaRecorderDemo extends Activity {
>
>     private static final String TAG = "MediaPlayerDemo";
>     private MediaPlayer mMediaPlayer;
>     private String path;
>
>         /** Called when the activity is first created. */
>
>         @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>         mPlay = (Button) findViewById(R.id.play);
>         mStart = (Button) findViewById(R.id.start);
>         mStop = (Button) findViewById(R.id.stop);
>
>         mPlay.setOnClickListener(mPlayListener);
>         mStart.setOnClickListener(mStartListener);
>         mStop.setOnClickListener(mStopListener);
>     }
>
>     @Override
>     protected void onDestroy() {
>         super.onDestroy();
>         // TODO Auto-generated method stub
>         if (mMediaPlayer != null) {
>             mMediaPlayer.release();
>             mMediaPlayer = null;
>         }
>
>     }
>
>     private OnClickListener mStopListener = new OnClickListener() {
>         public void onClick(View v) {
>                 recorder.stop();
>                 recorder.release();
>         }
>     };
>
>     private OnClickListener mPlayListener = new OnClickListener() {
>         public void onClick(View v) {
>             try {
>                     path = "/sdcard/audio4";
>                     if (path == "") {
>                         // Tell the user to provide an audio file URL.
>                         Toast
>                                 .makeText(
>                                         MediaRecorderDemo.this,
>                                         "Please edit MediaPlayer_Audio
> Activity, "
>                                                 + "and set the path
> variable to your audio file path."
>                                                 + " Your audio file
> must be stored on sdcard.",
>                                         Toast.LENGTH_LONG).show();
>
>                     }
>                     mMediaPlayer = new MediaPlayer();
>                     mMediaPlayer.setDataSource(path);
>                     mMediaPlayer.prepare();
>                     mMediaPlayer.start();
>
>             } catch (Exception e) {
>                 Log.e(TAG, "error: " + e.getMessage(), e);
>             }
>
>         }
>     };
>
>     private OnClickListener mStartListener = new OnClickListener() {
>         public void onClick(View v) {
>                 String path = "/sdcard/audio4";
>
>                 //ContentResolver contentResolver;
>                 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
>                 recorder.setOutputFormat
> (MediaRecorder.OutputFormat.THREE_GPP);
>                 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
>                 recorder.setOutputFile(path);
>
>                 recorder.prepare();
>                 recorder.start();
>                 }
>     };
>
>     private Button mPlay;
>     private Button mStop;
>     private Button mStart;
>     private MediaRecorder recorder = new MediaRecorder();
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to