public void startRecording(String saveFilePath) {
   setVisibility(View.VISIBLE);
   recorder = new MediaRecorder();
   recorder.setOnErrorListener(this);
   recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
   recorder.setMaxDuration(30 * 1000);
   recorder.setOutputFile(saveFilePath);
   recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
   try {
     recorder.prepare();
     recorder.start();
   } catch (IllegalStateException e) {
     recorder = null;
   } catch (IOException e) {
     e.printStackTrace();
     ToastUtil.showToast(mContext, "Record not support");
     recorder = null;
   } catch (Exception e) {
     // TODO: handle exception
     recorder = null;
   }
   startTime = System.currentTimeMillis();
   lastUpdate = System.currentTimeMillis();
   updateMicStatus();
 }
  public void startRecording(String path) {

    if (null != recorder) {

      // sendNotification(null);
      // Toast.makeText(getApplicationContext(), "BoundService2 ->녹음이
      // 시작",Toast.LENGTH_SHORT).show();
      Log.v(TAG, "BoundService2 녹음시작");

      // recorder = new MediaRecorder(); isRecorder = true;
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      recorder.setOutputFile(path);
      recorder.setOnErrorListener(errorListener);
      recorder.setOnInfoListener(infoListener);

      try {
        recorder.prepare();
        recorder.start();
      } catch (IllegalStateException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      Toast.makeText(getApplicationContext(), "녹음이 진행중입니다", Toast.LENGTH_SHORT).show();
    }

    //        Toast.makeText(getApplicationContext(), "BoundService2 ->서비스를
    // 죽임",Toast.LENGTH_SHORT).show();
    //        stopSelf();
    //        Log.v(TAG, "서비스를  죽임");

  }
 public boolean startRecording() {
   if (mediaRecorder == null) {
     if (!initRecorder()) return false;
   }
   mediaRecorder.setOnInfoListener(this);
   mediaRecorder.setOnErrorListener(this);
   mediaRecorder.start();
   return true;
 }
Beispiel #4
0
  private void startRecording() {
    Log.i("RecordVoiceController", "startRecording");
    try {
      recorder = new MediaRecorder();
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
      recorder.setOutputFile(myRecAudioFile.getAbsolutePath());
      myRecAudioFile.createNewFile();
      recorder.prepare();
      recorder.setOnErrorListener(
          new MediaRecorder.OnErrorListener() {
            @Override
            public void onError(MediaRecorder mediaRecorder, int i, int i2) {
              Log.i("RecordVoiceController", "recorder prepare failed!");
            }
          });
      recorder.start();
      startTime = System.currentTimeMillis();
      mCountTimer = new Timer();
      mCountTimer.schedule(
          new TimerTask() {
            @Override
            public void run() {
              mTimeUp = true;
              android.os.Message msg = mVolumeHandler.obtainMessage();
              msg.what = 55;
              Bundle bundle = new Bundle();
              bundle.putInt("restTime", 5);
              msg.setData(bundle);
              msg.sendToTarget();
              mCountTimer.cancel();
            }
          },
          56000);

    } catch (IOException e) {
      Log.e("RecordVoiceController", "e:", e);
      e.printStackTrace();
    } catch (RuntimeException e) {
      Log.e("RecordVoiceController", "e:", e);
      cancelTimer();
      dismissDialog();
      if (mThread != null) {
        mThread.exit();
        mThread = null;
      }
      if (myRecAudioFile != null) myRecAudioFile.delete();
      recorder.release();
      recorder = null;
    }

    mThread = new ObtainDecibelThread();
    mThread.start();
  }
  public void stopRecording() {
    if (mediaRecorder != null) {
      mediaRecorder.setOnErrorListener(null);
      mediaRecorder.setOnInfoListener(null);
      try {
        mediaRecorder.stop();
      } catch (IllegalStateException e) {
        EMLog.e("video", "stopRecording error:" + e.getMessage());
      }
    }
    releaseRecorder();

    if (mCamera != null) {
      mCamera.stopPreview();
      releaseCamera();
    }
  }
  /** Starts a new recording. */
  public boolean startRecording(int seconds) {
    isRecordingStart = true;
    // String state = android.os.Environment.getExternalStorageState();
    // if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
    // throw new IOException("SD Card is not mounted.  It is " + state +
    // ".");
    // }
    try {
      // make sure the directory we plan to store the recording in exists
      File directory = new File(path).getParentFile();
      if (!directory.exists() && !directory.mkdirs()) {
        isRecordingStart = false;
        throw new IOException("Path to file could not be created.");
      }

      recorder = new MediaRecorder();
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

      if (MEDIA_TYPE.equals(".amr")) {
        recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      } else {
        // recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setAudioChannels(1);
        // recorder.setAudioSamplingRate(SAMPLE_RATE);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        // recorder.setAudioEncodingBitRate(AUDIO_BITRATE);

      }

      recorder.setOutputFile(path);

      // recorder.setMaxDuration(seconds * 1000);
      recorder.prepare();
      recorder.start();
      recorder.setOnErrorListener(this);
      recorder.setOnInfoListener(this);
    } catch (Exception ex) {
      ex.printStackTrace();
      isRecordingStart = false;
      return false;
    }
    return true;
  }
Beispiel #7
0
 /**
  * 开始录音
  *
  * @version 1.0
  * @author zyh
  * @param chatId 会话Id
  */
 public void startRecording(String chatId) {
   if (recoder == null) {
     recoder = new MediaRecorder();
     recoder.setAudioSource(1);
     recoder.setOutputFormat(3);
     recoder.setAudioEncoder(1);
     recoder.setAudioChannels(1);
     recoder.setAudioEncodingBitRate(12200);
     recoder.setOnErrorListener(new RecorderErrorListener());
   } else {
     recoder.stop();
     recoder.reset();
   }
   recordFileName = System.currentTimeMillis() + ".amr";
   recordFilePath = getRecordFilePath(chatId);
   file = new File(recordFilePath);
   recoder.setOutputFile(file.getAbsolutePath());
   try {
     recoder.prepare();
     recoder.start();
     atomicBoolean.set(true);
     startTime = new Date().getTime();
     executor.execute(new CalculateRunnable(this));
     return;
   } catch (IllegalStateException localIllegalStateException) {
     Log.i("voice", "IllegalStateException thrown while trying to record a greeting");
     atomicBoolean.set(false);
     recoder.release();
     recoder = null;
     return;
   } catch (IOException localIOException) {
     Log.i("voice", "IOException thrown while trying to record a greeting");
     atomicBoolean.set(false);
     recoder.release();
     recoder = null;
   }
 }
Beispiel #8
0
 private boolean initAndStartMediaRecorder(RecordParams recordParams, int fileSizeLimit) {
   LogUtils.i(TAG, "<initAndStartMediaRecorder> start");
   try {
     /**
      * M:Changed to catch the IllegalStateException and NullPointerException. And the
      * IllegalStateException will be caught and handled in RuntimeException .@{
      */
     mSelectEffect = recordParams.mAudioEffect;
     mRecorder = new MediaRecorder();
     mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
     mRecorder.setOutputFormat(recordParams.mOutputFormat);
     mRecorder.setOutputFile(mSampleFile.getAbsolutePath());
     if (RecordParamsSetting.canSelectMode()) {
       MediaRecorderEx.setHDRecordMode(mRecorder, recordParams.mHDRecordMode, false);
     }
     /** M:Add for create/activate/delete AudioEffect at native layer. @{ */
     if (RecordParamsSetting.canSelectEffect()) {
       int iSelEffects = 0;
       if (mSelectEffect[RecordParamsSetting.EFFECT_AEC]) {
         iSelEffects |= (1 << RecordParamsSetting.EFFECT_AEC);
       }
       if (mSelectEffect[RecordParamsSetting.EFFECT_NS]) {
         iSelEffects |= (1 << RecordParamsSetting.EFFECT_NS);
       }
       if (mSelectEffect[RecordParamsSetting.EFFECT_AGC]) {
         iSelEffects |= (1 << RecordParamsSetting.EFFECT_AGC);
       }
       MediaRecorderEx.setPreprocessEffect(mRecorder, iSelEffects);
     }
     /** @} */
     mRecorder.setAudioEncoder(recordParams.mAudioEncoder);
     mRecorder.setAudioChannels(recordParams.mAudioChannels);
     mRecorder.setAudioEncodingBitRate(recordParams.mAudioEncodingBitRate);
     mRecorder.setAudioSamplingRate(recordParams.mAudioSamplingRate);
     if (fileSizeLimit > 0) {
       mRecorder.setMaxFileSize(fileSizeLimit);
     }
     mRecorder.setOnErrorListener(this);
     /** @}* */
     mRecorder.prepare();
     mRecorder.start();
   } catch (IOException exception) {
     LogUtils.e(TAG, "<initAndStartMediaRecorder> IO exception");
     // M:Add for when error ,the tmp file should been delete.
     handleException(true, exception);
     mListener.onError(this, ErrorHandle.ERROR_RECORDING_FAILED);
     return false;
   }
   /**
    * M: used to catch the null pointer exception in ALPS01226113, and never show any toast or
    * dialog to end user. Because this error just happened when fast tapping the file list button
    * after tapping record button(which triggered by tapping the recording button in audio play
    * back view).@{
    */
   catch (NullPointerException exception) {
     handleException(true, exception);
     return false;
   }
   /** @} */
   catch (RuntimeException exception) {
     LogUtils.e(TAG, "<initAndStartMediaRecorder> RuntimeException");
     // M:Add for when error ,the tmp file should been delete.
     handleException(true, exception);
     mListener.onError(this, ErrorHandle.ERROR_RECORDER_OCCUPIED);
     return false;
   }
   LogUtils.i(TAG, "<initAndStartMediaRecorder> end");
   return true;
 }