0

Hello i have create a small application in which i am recording audio. My problem is, in following code i can create a file in specific folder but when i am trying to play this audio file it says this media file is not supporting. plz help

public void startRecording() {

        System.out.println("STart Recording");

        if (recorder != null) {
            recorder.release();
        } else {
            recorder = new MediaRecorder();
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
            recorder.setOutputFile(getFilePath());

            try {
                recorder.prepare();
                recorder.start();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                recorder.release();
            }
        }

    }

    private void stopRecording() {

        System.out.println("Stop Recording");

        try {
            if (null != recorder) {
                recorder.stop();
                recorder.reset();
                recorder.release();
                recorder = null;
            }

        } catch (IllegalStateException e) {
            e.printStackTrace();
        }

    }

    private String getFilePath() {
        File rsd = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
        if (!rsd.isDirectory()) {
            rsd.mkdir();
        }
        File dcim = new File(rsd + "/hello.mp3");

        return dcim.getAbsolutePath();
    }
Nik
  • 638
  • 2
  • 11
  • 24

1 Answers1

0

Yup like Ralph House said in comment, you should save your file with .3gp extention. Change

File dcim = new File(rsd + "/hello.mp3");

To:

File dcim = new File(rsd + "/hello.3gp");
Peshal
  • 1,508
  • 1
  • 12
  • 22