Hi 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 ContentValues(3);
long current = System.currentTimeMillis();
values.put(MediaStore.Audio.Media.TITLE, "video" +
audiofile.getName());
values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current /
1000));
values.put(MediaStore.Audio.Media.MIME_TYPE, "video/mp4");
values.put(MediaStore.Audio.Media.DATA, audiofile.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri newUri = contentResolver.insert(base, values);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
newUri));
}
}
Any suggestions?
Bye
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---