无法播放音频录制+录制问题

时间:2017-09-04 15:26:17

标签: android

我的问题是我实际上无法播放应用中录制的音频。当我点击播放音频按钮时,没有音频声音。 这是我的JAVA代码:请看一下。

我得到的错误是:停止调用无效状态:mediarecorder.prepare()上的4;

我确实删除了任何不必要的部分:

代码链接:

mClick.setOnTouchListener(new View.OnTouchListener() {
@Override
     public boolean onTouch(View view, MotionEvent motionEvent) {

             if (motionEvent.getAction() == motionEvent.ACTION_DOWN) {
                 startRecording();
                 mRecordState.setText("מקליט..");
                 new CountDownTimer(4000, 1000) {

                     public void onTick(long millisUntilFinished) {
                         secondsRemaining++;
                         String secondsRemaining_String = Integer.toString(secondsRemaining);
                         //Toast.makeText(soundSelectBasic.this,secondsRemaining_String,Toast.LENGTH_LONG).show();

                         //here you can have your logic to set text to edittext
                     }

                     public void onFinish() {
                         if(recordCounter==1&&secondsRemaining>=2){
                                stopRecording();

                             }
                     }

                 }.start();
             } else if (motionEvent.getAction() == motionEvent.ACTION_UP) {

                 if (secondsRemaining>=2) {
                     recordCounter++;
                     stopRecording();

                 }
public void startRecording() {
    mediaRecorder = new MediaRecorder();
    mRecordState.setVisibility(View.VISIBLE);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mediaRecorder.setOutputFile(mFileName);


    try {
        mediaRecorder.prepare();
        mediaRecorder.start();
    } catch (IOException e) {
        Log.e(LOG_TAG, "prepare() failed");


} catch (IllegalStateException ioe) {
    Log.e(LOG_TAG, "prepare() failed");

}
Toast.makeText(soundSelectBasic.this,"ההקלטה החלה",Toast.LENGTH_LONG).show();




}


private void stopRecording() {

    try {
        mediaRecorder.stop();

    } catch (IllegalStateException ioe) {
        Log.e(LOG_TAG, "stop() failed");

    }
        mediaRecorder.release();
    mediaRecorder = null;

    mClick.setEnabled(false);
    mClick.setVisibility(View.INVISIBLE);
    grayPic.setVisibility(View.VISIBLE);
    mRecord.setEnabled(false);
    mRecordState.setText("ההקלטה הסתיימה.");
    new CountDownTimer(2000, 1000) {

        public void onTick(long millisUntilFinished) {
        }

        public void onFinish() {
            displayConfirmDialog();            
        }

    }.start();}}` 

错误:

09-04 17:58:55.644 2275-2275/com.commandofox.myapplication E/Record_log: prepare() failed
09-04 17:58:56.804 2275-2275/com.commandofox.myapplication E/MediaRecorder: stop called in an invalid state: 4
09-04 17:58:56.804 2275-2275/com.commandofox.myapplication E/Record_log: stop() failed
09-04 17:58:59.964 2275-2275/com.commandofox.myapplication E/ViewRootImpl: sendUserActionEvent() mView == null

1 个答案:

答案 0 :(得分:0)

错误无效状态:4(中断系统调用)最有可能:

  • 没有在Manifest

    中添加外部/内部存储数据的权限

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

  • 没有添加permision for mediarecorder以在Manifest中记录

    <uses-permission android:name="android.permission.RECORD_AUDIO" />

  • 名称中的错误,我无法检查