永远不会调用Media Recorder stop()

时间:2013-01-19 05:58:29

标签: android broadcastreceiver android-mediarecorder

我正在播放我的广播音频文件,但我没有收到任何错误,但我的记录从未调用过我的代码:

String file_name= "recording";
        audiofile = File.createTempFile(file_name, ".3gp", sampleDir);
        String path=Environment.getExternalStorageDirectory().getAbsolutePath();
        //recorder = null;

         int audioSource = MediaRecorder.AudioSource.VOICE_CALL;

         recorder.setAudioSource(audioSource);
         recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
         recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
         recorder.setOutputFile(audiofile.getAbsolutePath()); 


             recorder.prepare();

             recorder.start(); 

我的停止功能包含:

public void stopRecord()throws IOException{
             if(recorder!=null)
             {

             recorder.stop();

             recorder.release();
             recorder.reset();

             Log.d(TAG, "recording stopped");
             }
             else
             {
                 Log.d(TAG, "recording stopped error");
             }

我在offhook阶段调用启动录音机并在空闲时停止录音机,但它进入空闲状态并且根本没有调用停止。

case TelephonyManager.CALL_STATE_IDLE:  
                     prev_state=state;
                     Log.d(TAG, "CALL_STATE_IDLE==>"+incoming_nr);

                     Log.d(TAG, "recording stopped");  // Executes till here and skips the below part
                     try {
                        stopRecord();
                         Log.d(TAG, "recording stopped");  
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                     Log.d(TAG, "recording stopped");  

我已经给予了所有许可,请帮助我 在此先感谢

1 个答案:

答案 0 :(得分:0)

当没有活动时调用

TelephonyManager.EXTRA_STATE_IDLE,并在TelephonyManager.EXTRA_STATE_OFFHOOK之前调用此活动。

在这里,您在stopRecord()状态中调用TelephonyManager.EXTRA_STATE_IDLE函数,因此您正在访问mRecorder.stop();,但此时Recorder对象为null且未初始化。 Checdk这篇文章更多的澄清Null Exception when recording using mediaRecorder。另请查看评论。

就没有错误而言,您在try/catch块中调用它。因此,只会生成堆栈跟踪。

相关问题