android 录音代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

import android.app.Activity;  
import android.media.MediaRecorder;  
import android.os.Bundle;  
import android.os.Environment;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.widget.Button;  
  
public class MainActivity extends Activity {  
  
    private Button start, end;  
    private MediaRecorder mediaRecorder;  
    private String fileName;  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
        start= (Button) findViewById(R.id.start);  
        end = (Button) findViewById(R.id.end);  
        fileName= Environment.getExternalStorageDirectory().getAbsolutePath() + "/audioRecorder.3gp";  
        start.setOnClickListener(new OnClickListener() {  
              
            @Override  
            public void onClick(View v) {  
                //一共七步  
                mediaRecorder = new MediaRecorder();  
                mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);//设置麦克风  
                mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);//输出音频格式  
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);//编码格式  
                mediaRecorder.setOutputFile(fileName);//输出路径  
                try {  
                    mediaRecorder.prepare();//准备  
                } catch (Exception e) {  
                    e.printStackTrace();  
                }  
                mediaRecorder.start();//开始录音  
            }  
        });  
        //结束录音  
        end.setOnClickListener(new OnClickListener() {  
              
            @Override  
            public void onClick(View v) {  
                mediaRecorder.stop();  
                mediaRecorder.release();  
            }  
        });  
    }  
}