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

  • Home
  • SEARCH
  • 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 8286295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:41:48+00:00 2026-06-08T11:41:48+00:00

I am trying to work with audiorecorder, but I am getting illegal argument exceptions

  • 0

I am trying to work with audiorecorder, but I am getting illegal argument exceptions stating that the audiorecorder is not initialised.

My code is like the one shown here

private static final int RECORDER_SAMPLERATE = 44100;
private static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_STEREO;
private static final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;

recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,RECORDER_SAMPLERATE,  RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING, bufferSize);                        
recorder.startRecording();

I have seen another answer which seems to work for some people but it isn’t working for me
AudioRecord object not initializing

  • 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-08T11:41:49+00:00Added an answer on June 8, 2026 at 11:41 am

    Try this instead:

    private MediaRecorder mRecorder = null;
    private void startRecording() {
            String fileSaveName = generateNameForAudioFile();
            mRecorder = new MediaRecorder();
            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mRecorder.setOutputFile(fileSaveName);
            mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    
            try {
                mRecorder.prepare();
            } catch (IOException e) {
                Log.e(LOG_TAG, "prepare() failed");
            }
    
            mRecorder.start();
        }
    
    
    
    private void stopRecording() {
            startRecording.setEnabled(true);
            try {
                if (mRecorder != null) {
                    mRecorder.stop();
                    mRecorder.release();
                    mRecorder = null;
                }
            } catch (Exception e) {
            }
    
        }
    
    public String generateNameForAudioFile() {
    
            String audioName = GetrandFilename();
            mFileName = Environment.getExternalStorageDirectory().getPath() + "/"
                    + audioName + "myaudio" + ".3gp";
    
            );
            return mFileName;
        }
    
    
    
    @Override
        public void onPause() {
            super.onPause();
    
                try {
                    if (mRecorder != null) {
                        mRecorder.stop();
                        mRecorder.release();
                        mRecorder = null;
                    }
                } catch (Exception e) {
                }
                  }
    

    Let me know if this post is of any help.

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

Sidebar

Related Questions

Im trying to work with following code i getting this error at xsltProcessor.importStylesheet Error
trying to work out how to install zipArchive extension with MAMP, but not having
I am trying to work a webflow project but I keep getting the following
Trying to work with groupby so that I can group together files that were
When trying to work with Qt's signal/slot mechanisms over more than one level of
Im trying to work out how to get the value from one setting in
I am trying to work out why I can not access the nested function
I am trying to work out how to parallelize some code from data mining
When trying to work in QtCreator, there is a problem with code completion for
Trying to work with array, but it gives me Statement requires expression of integer

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.