How to save audio/sound

All your problems with Audio, Video and Images.

How to save audio/sound

Postby nunotms » Wed Feb 10, 2010 10:28 am

I want to use MediaRecoder to record the sound and save it locally.
I have read the code on android dev webpage

Code: Select all
    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);
   
    if (newUri == null) {
        // 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();


But the code doesn't seems work on " String path = contentResolver.getDataFilePath(newUri);"
So what can i do?
nunotms
Freshman
Freshman
 
Posts: 4
Joined: Wed Feb 10, 2010 10:22 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 9 guests