Note that there are some explanatory texts on larger screens.

plurals
  1. POCrash while recording media in Android app
    primarykey
    data
    text
    <p>I'm just starting off and I'm using the developers tutorials. I've modified the recording code as below, but I am getting an error and I'm not sure. I don't have an in depth level of Java, and I'm only really about 3 weeks into Objects and Classes. This app is for a project, for which we have no spec.</p> <pre><code>private static final String LOG_TAG = "Recording"; //start recording stuff private RecordButton mRecordButton = null; private MediaRecorder mRecorder = null; private void onRecord(boolean start) { if (start) startRecording(); else stopRecording(); } private void startRecording() { mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mRecorder.setOutputFile("/sdCard0/panic_record/" + System.currentTimeMillis()+ ".3gp"); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); try { mRecorder.prepare(); } catch (IOException e) { 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); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_record); getActionBar().setDisplayHomeAsUpEnabled(true); LinearLayout ll = new LinearLayout(this); mRecordButton = new RecordButton(this); ll.addView(mRecordButton, new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0)); setContentView(ll); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_record, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } </code></pre> <p>LogCat output is</p> <pre> 09-26 20:05:37.620: E/Recording(1152): prepare() failed 09-26 20:05:37.620: E/MediaRecorder(1152): start called in an invalid state: 4 09-26 20:05:37.620: D/AndroidRuntime(1152): Shutting down VM 09-26 20:05:37.620: W/dalvikvm(1152): threadid=1: thread exiting with uncaught exception (group=0x41c18300) 09-26 20:05:37.630: E/AndroidRuntime(1152): FATAL EXCEPTION: main 09-26 20:05:37.630: E/AndroidRuntime(1152): java.lang.IllegalStateException 09-26 20:05:37.630: E/AndroidRuntime(1152): at android.media.MediaRecorder.start(Native Method) 09-26 20:05:37.630: E/AndroidRuntime(1152): at cs4084.panic.button.Record.startRecording(Record.java:55) 09-26 20:05:37.630: E/AndroidRuntime(1152): at cs4084.panic.button.Record.onRecord(Record.java:34) 09-26 20:05:37.630: E/AndroidRuntime(1152): at cs4084.panic.button.Record.access$0(Record.java:31) 09-26 20:05:37.630: E/AndroidRuntime(1152): at cs4084.panic.button.Record$RecordButton$1.onClick(Record.java:71) 09-26 20:05:37.630: E/AndroidRuntime(1152): at android.view.View.performClick(View.java:4211) 09-26 20:05:37.630: E/AndroidRuntime(1152): at android.view.View$PerformClick.run(View.java:17267) 09-26 20:05:37.630: E/AndroidRuntime(1152): at android.os.Handler.handleCallback(Handler.java:615) 09-26 20:05:37.630: E/AndroidRuntime(1152): at android.os.Handler.dispatchMessage(Handler.java:92) 09-26 20:05:37.630: E/AndroidRuntime(1152): at android.os.Looper.loop(Looper.java:137) 09-26 20:05:37.630: E/AndroidRuntime(1152): at android.app.ActivityThread.main(ActivityThread.java:4898) 09-26 20:05:37.630: E/AndroidRuntime(1152): at java.lang.reflect.Method.invokeNative(Native Method) 09-26 20:05:37.630: E/AndroidRuntime(1152): at java.lang.reflect.Method.invoke(Method.java:511) 09-26 20:05:37.630: E/AndroidRuntime(1152): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 09-26 20:05:37.630: E/AndroidRuntime(1152): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 09-26 20:05:37.630: E/AndroidRuntime(1152): at dalvik.system.NativeStart.main(Native Method) </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload