小编Gok*_*hna的帖子

java.lang.RuntimeException:setAudioSource失败

我是android开发的新手.我只是想用6.0.1 Marshmallow设备用android studio(2.1.1)测试录制音频.

public class MainActivity extends AppCompatActivity {

    Button start, stop;
    public MediaRecorder recorder = null;
    public String fileextn = ".mp4";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        start = (Button) findViewById(R.id.start_button);
        stop = (Button) findViewById(R.id.stop_button);

        start.setOnClickListener(new View.OnClickListener(){

                                     @Override
                                     public void onClick(View v) {

                                         switch (v.getId()) {
                                             case R.id.start_button:
                                                 startRecord();
                                             case R.id.stop_button:
                                                 stoprecord();
                                         }
                                     }

                                 }
        );

    }

    public void startRecord() {
        recorder = new MediaRecorder();
        recorder.reset();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setOutputFile(getFilePath());

        try {
            recorder.prepare();
            recorder.start();
        } catch (IllegalStateException …
Run Code Online (Sandbox Code Playgroud)

android android-studio

16
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

android-studio ×1