java.lang.IllegalStateException in MediaPlayer.isplaying() method

前端 未结 3 1320
夕颜
夕颜 2021-02-12 10:30
public static MediaPlayer mp=null;
public static void playGeneric(int name, final ImageButton button,final ImageButton pervious,Context context) {
    button.setEnabled(         


        
3条回答
  •  时光说笑
    2021-02-12 11:30

    use runOnUiThread for mediaRecorder prepare.

    private boolean prepareMediaRecorder() {
    
        mediaRecorder = new MediaRecorder();
    
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
    
                mediaRecorder.reset();
                mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    
                mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
    
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    
                mediaRecorder.setOutputFile(filePath);
    
                try {
                    mediaRecorder.prepare();
                } catch (IOException e) {
                    mediaRecorder = null;
                    return;
                }
                mediaRecorder.start();
                recording = true;
            }
        });
    
        return true;
    }
    

提交回复
热议问题