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();
    }
4

1 回答 1

0

是的,就像 Ralph House 在评论中所说的那样,您应该使用 .3gp 扩展名保存您的文件。改变

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

至:

File dcim = new File(rsd + "/hello.3gp");
于 2013-07-31T22:49:50.247 回答