n sorry for bad english..... On Dec 5, 5:25 pm, rachana govilkar <rachana.govil...@gmail.com> wrote: > yes thank u for quick reply.... :) > coz i did mention this question on my thread also..... > n yes it is giving me exception....IllegalStateException > but y so?? > i mean i have just wrote program same as provided on d link.... > my program is... > > package com.privacygram.activity; > > import java.io.IOException; > > import android.app.Activity; > import android.content.Context; > import android.media.MediaPlayer; > import android.media.MediaRecorder; > import android.os.Bundle; > import android.os.Environment; > import android.util.Log; > import android.view.View; > import android.view.ViewGroup; > import android.widget.Button; > import android.widget.LinearLayout; > > public class AudioCapturing extends Activity{ > > private static final String LOG_TAG = "AudioRecordTest"; > private static String mFileName = null; > > private RecordButton mRecordButton = null; > private MediaRecorder mRecorder = null; > > private PlayButton mPlayButton = null; > private MediaPlayer mPlayer = null; > > private void onRecord(boolean start) { > if (start) { > startRecording(); > } else { > stopRecording(); > } > } > > private void onPlay(boolean start) { > if (start) { > startPlaying(); > } else { > stopPlaying(); > } > } > > private void startPlaying() { > mPlayer = new MediaPlayer(); > try { > mPlayer.setDataSource(mFileName); > mPlayer.prepare(); > mPlayer.start(); > } catch (IOException e) { > Log.e(LOG_TAG, "prepare() failed"); > } > } > > private void stopPlaying() { > mPlayer.release(); > mPlayer = null; > } > > private void startRecording() { > mRecorder = new MediaRecorder(); > mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); > > mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); > mRecorder.setOutputFile(mFileName); > mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); > > try { > mRecorder.prepare(); > > } catch (IOException e) { > Log.e(LOG_TAG, "prepare() failed"); > > } catch (Exception e) { > // TODO: handle exception > Log.e(LOG_TAG, "prepare() failed"); > } > > mRecorder.start(); > } > > private void stopRecording() { > mRecorder.stop(); > mRecorder.release(); > mRecorder = null; > } > > class RecordButton extends Button { > boolean mStartRecording = true; > > OnClickListener clicker = new OnClickListener() { > public void onClick(View v) { > onRecord(mStartRecording); > if (mStartRecording) { > setText("Stop recording"); > } else { > setText("Start recording"); > } > mStartRecording = !mStartRecording; > } > }; > > public RecordButton(Context ctx) { > super(ctx); > setText("Start recording"); > setOnClickListener(clicker); > } > } > > class PlayButton extends Button { > boolean mStartPlaying = true; > > OnClickListener clicker = new OnClickListener() { > public void onClick(View v) { > onPlay(mStartPlaying); > if (mStartPlaying) { > setText("Stop playing"); > } else { > setText("Start playing"); > } > mStartPlaying = !mStartPlaying; > } > }; > > public PlayButton(Context ctx) { > super(ctx); > setText("Start playing"); > setOnClickListener(clicker); > } > } > > public AudioCapturing() { > Log.d("state is:",Environment.getExternalStorageState()); > mFileName = > Environment.getExternalStorageDirectory().getAbsolutePath(); > mFileName += "/audiorecordtest.3gp"; > > //mFileName = > "android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI"; > } > > public void onCreate(Bundle icicle) { > super.onCreate(icicle); > > LinearLayout ll = new LinearLayout(this); > mRecordButton = new RecordButton(this); > ll.addView(mRecordButton, > new LinearLayout.LayoutParams( > ViewGroup.LayoutParams.WRAP_CONTENT, > ViewGroup.LayoutParams.WRAP_CONTENT, > 0)); > mPlayButton = new PlayButton(this); > ll.addView(mPlayButton, > new LinearLayout.LayoutParams( > ViewGroup.LayoutParams.WRAP_CONTENT, > ViewGroup.LayoutParams.WRAP_CONTENT, > 0)); > setContentView(ll); > } > > @Override > public void onPause() { > super.onPause(); > if (mRecorder != null) { > mRecorder.release(); > mRecorder = null; > } > > if (mPlayer != null) { > mPlayer.release(); > mPlayer = null; > } > } > > } > > error is on 28,92 is for onRecord() > as prepare is failed start() is also giving error.... > > i dont knw what shud i write now.... > thnks for help btw..... > > On Dec 5, 3:52 pm, Raghav Sood <raghavs...@androidactivist.org> wrote: > > > > > > > > > I'd say that your error is coming from one of lines 74, 30, 28 or 88. At > > least that's what the LogCat says. If you look closer, you will notice that > > your prepare() method has failed to work and has given you an exception. > > > 12-05 16:11:39.442: ERROR/AudioRecordTest(309): prepare() failed > > > > 12-05 16:11:39.442: ERROR/MediaRecorder(309): start called in an > > > invalid state: 4 > > > 12-05 16:11:39.512: DEBUG/AndroidRuntime(309): Shutting down VM > > > 12-05 16:11:39.512: WARN/dalvikvm(309): threadid=1: thread exiting > > > with uncaught exception (group=0x4001d800) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): FATAL EXCEPTION: main > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): > > > java.lang.IllegalStateException > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > android.media.MediaRecorder.start(Native Method) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > com.privacygram.activity.AudioCapturing.startRecording(AudioCapturing.java: > > > 74) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > com.privacygram.activity.AudioCapturing.onRecord(AudioCapturing.java: > > > 30) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > com.privacygram.activity.AudioCapturing.access$0(AudioCapturing.java: > > > 28) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > com.privacygram.activity.AudioCapturing$RecordButton > > > $1.onClick(AudioCapturing.java:88) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > android.view.View.performClick(View.java:2408) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at android.view.View > > > $PerformClick.run(View.java:8816) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > android.os.Handler.handleCallback(Handler.java:587) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > android.os.Handler.dispatchMessage(Handler.java:92) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > android.os.Looper.loop(Looper.java:123) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > android.app.ActivityThread.main(ActivityThread.java:4627) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > java.lang.reflect.Method.invokeNative(Native Method) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > java.lang.reflect.Method.invoke(Method.java:521) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > com.android.internal.os.ZygoteInit > > > $MethodAndArgsCaller.run(ZygoteInit.java:868) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) > > > 12-05 16:11:39.722: ERROR/AndroidRuntime(309): at > > > dalvik.system.NativeStart.main(Native Method) > > > i have written all permissions in manifest.xml.... > > > can u plz help me wat am i supposed to do?? > > > thnk u.... > > > You should also checkout this book. It will help you in > > life:http://www.amazon.com/Little-Oxford-English-Dictionary-Eighth/dp/0198... > > > Thanks > > > -- > > Raghav > > Soodhttp://www.androidactivist.org/-Authorhttp://www.appaholics.in/-Founder
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en