Example Audio Capture Setup and Start

The example below illustrates how to set up, then start audio capture.

recorder = new MediaRecorder(); ContentValues values = new ContentValues(3);

values.put(MediaStore.MediaColumns.TITLE, SOME_NAME_HERE);

values.put(MediaStore.MediaColumns.TIMESTAMP, System.currentTimeMillis()); values.put(MediaStore.MediaColumns.MIME_TYPE, recorder.getMimeContentType());

ContentResolver contentResolver = new ContentResolver();

Uri base = MediaStore.Audio.INTERNAL_CONTENT_URI; Uri newUri = contentResolver.insert(base, values);

// need to handle exception here - we were not able to create a new // content entry

String path = contentResolver.getDataFilePath(newUri);

// could use setPreviewDisplay() to display a preview to suitable View here recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path);

recorder.prepare(); recorder.start();

0 0

Post a comment