Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:44:28+00:00 2026-06-01T03:44:28+00:00

I am using MediaRecorder in my Android app. I referred to the online documentation

  • 0

I am using MediaRecorder in my Android app. I referred to the online documentation for the public void setOutputFile (String path) of the MediaRecorder class but couldn’t find information as to whether it overwrites an existing file at the same path or appends to the existing file, if it exists.

So, two questions:

  1. Does public void setOutputFile (String path) overwrite the file at path, if it exists, or it appends to the file at path?
  2. Is there any way to resume an already paused recording which is saved at a particular path?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:44:30+00:00Added an answer on June 1, 2026 at 3:44 am

    So far from my finding, I conclude that the Android API currently does not provide an option to resume recording using MediaRecorder.

    So manage my target of merging two recorded audio, I went with direct merging of two files by skipping the headers from the second file.

    Following is my code for reference:

        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
    
        /* If the voiceMessage in consideration is a PAUSED one, then we should 
         * record at a new alternate path so that earlier recording does not get overwritten, and can be used later for merging */
        Log.d(LOG_TAG, "VoiceMessageManager:recordVoiceMessage() - state of voice message - " + voiceMessage.getVoiceMessageState());
    
        mRecorder.setOutputFile(filePath);
    
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mRecorder.prepare();
        mRecorder.start();
    

    And my code for combining the two audio files is as follows:

    protected Void doInBackground(String... filePaths) {
             try {
                    String originalVoiceMessageRecording = filePaths[0];
                    String newVoiceMessageRecording = filePaths[1];
    
                    File outputFile = new File(originalVoiceMessageRecording);
                    FileOutputStream fos = new FileOutputStream(outputFile, true); // Second parameter to indicate appending of data
    
                    File inputFile = new File(newVoiceMessageRecording);
                    FileInputStream fis = new FileInputStream(inputFile);
    
                    Log.d(LOG_TAG, "Length of outputFile: " + outputFile.length() + " and Length of inputFile: " + inputFile.length() );
    
                    byte fileContent[]= new byte[(int)inputFile.length()];
                    fis.read(fileContent);// Reads the file content as byte from the list.
    
                    /* copy the entire file, but not the first 6 bytes */
                    byte[] headerlessFileContent = new byte[fileContent.length-6];
                    for(int j=6; j<fileContent.length;j++){
                        headerlessFileContent[j-6] = fileContent[j];
                    }
                    fileContent = headerlessFileContent;
    
                    /* Write the byte into the combine file. */
                    fos.write(fileContent);
    
                    /* Delete the new recording as it is no longer required (Save memory!!!) :-) */
                    File file = new File(newVoiceMessageRecording); 
                    boolean deleted = file.delete();
    
                    Log.d(LOG_TAG, "New recording deleted after merging: " + deleted);
                    Log.d(LOG_TAG, "Successfully merged the two Voice Message Recordings");
                    Log.d(LOG_TAG, "Length of outputFile after merging: " + outputFile.length());
                } catch (Exception ex) {
                    Log.e(LOG_TAG, "Error while merging audio file: " + ex.getMessage());
                }
            return null;
         }
    

    In short what I am doing is – skipping the headers of the second file (The length of the header in AMR file is 6 bytes).

    This worked for me and I tested it on Android version 2.3

    Hope this helps others!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am able to Record Android's Camera Using Mediarecorder Class. I heard that sipdroid
I'm using MediaRecorder class to record an audio file and I used final String
I am using the MediaRecorder for audio recording in android. I receive very poor
I am doing audio recording using MediaRecorder, but unfortunately when I playback the recorded
I'm trying to develop an Audio Capture application using the AudioRecord class from android
My app records calls using standard MediaRecorder. After a few seconds after incoming call
can anybody provide me code for recording audio using MediaRecorder of android by setting
I try to record video using MediaRecorder Class. However I find out that I
Using top it's easy to identify processes that are hogging memory and cpu, but
I'm new here. I have been trying to create a video capture app using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.