コード例 #1
0
 /**
  * Uses the settings from a CamcorderProfile object for recording. This method should be called
  * after the video AND audio sources are set, and before setOutputFile(). If a time lapse
  * CamcorderProfile is used, audio related source or recording parameters are ignored.
  *
  * @param profile the CamcorderProfile to use
  * @see android.media.CamcorderProfile
  */
 public void setProfile(CamcorderProfile profile) {
   setOutputFormat(profile.fileFormat);
   setVideoFrameRate(profile.videoFrameRate);
   setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
   setVideoEncodingBitRate(profile.videoBitRate);
   setVideoEncoder(profile.videoCodec);
   if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW
       && profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA) {
     // Nothing needs to be done. Call to setCaptureRate() enables
     // time lapse video recording.
   } else {
     setAudioEncodingBitRate(profile.audioBitRate);
     setAudioChannels(profile.audioChannels);
     setAudioSamplingRate(profile.audioSampleRate);
     setAudioEncoder(profile.audioCodec);
   }
 }
コード例 #2
0
ファイル: AudioRecorder.java プロジェクト: TsaoChiyen/-
  public void start() throws IOException {
    recorder = new MediaRecorder();
    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 + ".");
    }
    File directory = new File(path).getParentFile();

    if (!directory.exists() && !directory.mkdirs()) {
      throw new IOException("Path to file could not be created");
    }

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    //		recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
    //		recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    recorder.setAudioSamplingRate(SAMPLE_RATE_IN_HZ);
    recorder.setOutputFile(path);
    recorder.prepare();
    recorder.start();
  }
コード例 #3
0
ファイル: Recorder.java プロジェクト: zst123/p201-packages
 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;
 }