Android examples for android.media:Audio
stop Recording Audio and save audio file
import java.io.File; import android.content.ContentValues; import android.content.Context; import android.media.MediaRecorder; import android.net.Uri; import android.provider.MediaStore; import android.text.TextUtils; import android.util.Log; public class Main { private static MediaRecorder mRecorder; public static Uri stopRecordingAudio(Context ctx) { try {/*from ww w. j ava 2 s. co m*/ mRecorder.stop(); mRecorder.reset(); // set state to idle mRecorder.release(); mRecorder = null; } catch (Exception e) { e.printStackTrace(); } return saveAudio(ctx); } /** * * @param ctx * @return The media content Uri to the newly created audio, or null if failed * for any reason. */ private static Uri saveAudio(Context ctx) { File audioFile = new File("yourFile.mp3"); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, audioFile.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, ""); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg"); values.put(MediaStore.MediaColumns.SIZE, audioFile.length()); values.put(MediaStore.Audio.Media.ARTIST, ""); values.put(MediaStore.Audio.Media.IS_RINGTONE, false); // Now set some extra features it depend on you values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false); Uri uri = MediaStore.Audio.Media.getContentUriForPath(audioFile.getAbsolutePath()); Uri uri2 = ctx.getContentResolver().insert(uri, values); if (uri2 == null || TextUtils.isEmpty(uri2.toString())) { Log.w("", "Something went wrong while inserting data to content resolver"); } return uri2; } }