2

实际上我正在从事录音工作,我想根据需要选择我的音频文件,我创建了用于显示格式选项的弹出框,但我无法选择选择性的,在我的情况下它将采用默认格式或第一种格式。谁能帮帮我吗?

public String getFilename(){
    String filepath = Environment.getExternalStorageDirectory().getPath();
    File file = new File(filepath,AUDIO_RECORDER_FOLDER);

    if(!file.exists()){
        file.mkdirs();
    }
    gfilename = (file.getAbsolutePath() + "/" + System.currentTimeMillis() + file_exts[currentFormat]);
    return (gfilename );
}

@SuppressLint("NewApi")
private void startRecording(){
    recorder = new MediaRecorder();         
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
    recorder.setOutputFormat(output_formats[currentFormat]);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(getFilename());          
    //recorder.setOnErrorListener(errorListener);
    //recorder.setOnInfoListener(infoListener);

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

private void stopRecording(){
    if(null != recorder)
    {
        mDbHelper.updateTestFileName(mRowId, gfilename); 
        recorder.stop();
        recorder.reset();
        recorder.release();             
        recorder = null;
        }
    displayFormatDialog();

}

private void displayFormatDialog(){
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String formats[] = {"MPEG 4", "3GPP", "AMR", "Mp3"};

    builder.setTitle(getString(R.string.choose_format_title))
           .setSingleChoiceItems(formats, currentFormat, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                currentFormat = which;
                //setStopButtonCaption();

                dialog.dismiss();
            }
           })
           .show();
}
4

0 回答 0