Question

I have an app which records Audio and saves it in SD Card.When i check the Recorded Audio's the bit Rate of the recorded Audio files are always Zero (0 kbps).The file format is MP3. Below is my code

 mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mRecorder.setMaxDuration(60000);
mRecorder.setAudioSamplingRate(44100);
    mRecorder.setAudioEncodingBitRate(96000);   

try {
    mRecorder.prepare();
} catch (IOException e) {
    Log.e(LOG_TAG, "prepare() failed");
}

mRecorder.start();

Please Suggest What could be the problem and what is the solution.Thank you.

Was it helpful?

Solution

I tried your specs, and i found a solution in my system.

Probably you just have this simple problem that i could observe:

You are using default encoder, and default outputformat. Its ok for me if you use default encoder. But what i can guess, is that your default output format is 3gpp, and you ar saving the file as .mp3

If you do this, many players will play it perfectly, but it almost imposible to extract any other information from the file. So, what i suggest is, change the file extension to 3gp, and check the properties.

If you have there a bitrate, here you have your answer!

OTHER TIPS

The problem here is the way you're checking the bitrate, not the code. Quite a few applications fail to report MP3 bitrate correctly, however if you observe the size of a file and you can play it using any player, you can be sure that it's not 0kbps, because 0 bits per second would mean the file would be empty (well, it might have some headers in it, but you wouldn't be able to play it).

For checking music files I generally recommend foobar2000 on windows and ffmpeg for the rest.

Do this way

Declaration

private MediaRecorder mRecorder = null;
private String mFileName;

Generate unique file name

private String getRecordDefaultFileName() {
        String fileName;
        File wallpaperDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "MyRecordings" + "/");
        if (!wallpaperDirectory.exists()) {
            wallpaperDirectory.mkdirs();
        }
        if (wallpaperDirectory.listFiles() != null) {
            fileName = "record" + wallpaperDirectory.listFiles().length;
        } else {
            fileName = "record" + 1;
        }

        return wallpaperDirectory.getAbsolutePath() + File.separator + fileName + ".3gp";
    }

Start Recording

private void startRecording() {
        try {
            mRecorder = new MediaRecorder();
            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mFileName = getRecordDefaultFileName();
            mRecorder.setOutputFile(mFileName);
            mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

            try {
                mRecorder.prepare();
            } catch (IOException e) {
                System.out.println("prepare() failed");
            }

            mRecorder.start();
        } catch (Exception e) {
        }

    }

Strop Recording

private void stopRecording() {
    try {
        if (mRecorder != null) {
            mRecorder.stop();
            mRecorder.release();
            mRecorder = null;
        }
    } catch (Exception e) {
    }
}

Permissions Required in mainfest.xml

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top