MediaRecorder video/audio recording

by Maurizio Bellemo » Thu, 06 Aug 2009 17:25:38 GMT


Sponsored Links
 i all,

I'm trying to create an application to save video recording on a file
in Android. The problem is that only for audio recording, it's fine,
but when I try to add the video part the prepare() fails. Below the
code....

public classTest extends Activity {
MediaRecorder mr;
File audiofile = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Configuring audio/video access
try {
setStreaming();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

mr.stop();
mr.reset();
mr.release();
processaudiofile();
}

@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();

// Configuring audio/video access
try {
setStreaming();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Starting the MediaRecorder
mr.start();
}

// @Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();

// Starting the MediaRecorder
mr.start();
}

@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();

// Stopping MediaRecorder
mr.stop();
mr.reset();
mr.release();
processaudiofile();
}

private void setStreaming() throws IOException {
// Creating a MediaRecorder object
mr = new MediaRecorder();
// Configuring audio/video source (MIC and camera)
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
//mr.setCamera(Camera.open());
mr.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

// Configuring the output format
mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
// Configuring audio/video codecs
mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mr.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
// Setting the output file
if (audiofile == null) {
File sampleDir = Environment.getExternalStorageDirectory();
try
{
audiofile = File.createTempFile("moca", ".mp4", sampleDir);
}
catch (IOException e)
{
Log.e("ERROR","sdcard access error");
return;
}
}
mr.setOutputFile(audiofile.getAbsolutePath());
// the recorder is ready to register

mr.prepare();
mr.start();
}

protected void processaudiofile() {
ContentValues values = new ContentValu



Other Threads

1. Internal JVM memory questions

1.       In the event that the Android system is running low on
memory, Android starts shutting down activities and/or processes.  Can
Android shut down individual components, as opposed to the whole
process?  In other words, can Android close down an activity but leave
the service running? (I believe the answer is 98% yes, but there were
some ambiguities on the Android dev framework page)

2.       Presuming the answer to 1 is yes, imagine a scenario where an
Activity is shut down, but a Service is still running.  If the Android
OS shuts down that Activity, do all of the Java Threads that were
created by that Activity get terminated?

If so, I like to know more about how that works, because as I
understood it, all Services and Activities run on the same thread, so
how would one child thread get marked to an activity but not the
service. (We have a thread that is going to work with both Services
and Activities)

3.       Do the JVMs built in with Android (Davik JVMs) have the
ability to release memory to the system that it longer uses?  Win32
Sun Java JVMs do not do this (once they ask for more memory, they will
never release it back to the system; you will see on Win32 a java.exe
grow in memory used, but never shrink)

The reason we ask, is that we want to know this: If one calls finish()
on an Activity, and that Activity is closed, but the process that
holds that Activity is still running, does the process itself release
the memory back to the system? (because on Win32, you will never see
java.exe release memory after a GC; it is only tagged internally to
the JVM as free, not to the OS)


--~--~---------~--~----~------------~-------~--~----~

2. How to detect idle screen?

How to detect idle screen from an app?

Thanks,

Sherry
--~--~---------~--~----~------------~-------~--~----~

3. How to programmatic obtain current app path?

4. PreferenceActivity, using the built-ins with style

5. how to run android source code in linux eclipse??

6. Is it legal to customize and publish the built-in applications?

7. Android 1.5 (Cupcake) permissions on Location/GPS settings