/** * 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); } }
private void resetRecorder() { recorder.setAudioSource(MediaRecorder.AudioSource.MIC); if (spinType == "mp3") { recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); } else { recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); } recorder.setAudioEncodingBitRate(quality); recorder.setOutputFile(path.getAbsolutePath()); try { recorder.prepare(); } catch (Exception e) { e.printStackTrace(); } }
public void startRecord() { mediaRecorder = new MediaRecorder(); mediaRecorder.reset(); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setAudioEncodingBitRate(96000); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mediaRecorder.setOutputFile( AppGlobals.getDataDirectory("CallRec") + "/" + AppGlobals.sCurrentNumber + "_" + Helpers.getTimeStamp() + ".aac"); try { mediaRecorder.prepare(); } catch (IOException e) { e.printStackTrace(); } mediaRecorder.start(); Log.i(AppGlobals.getLogTag(getClass()), "Recording started....."); isRecording = true; }
/** * Default constructor * * <p>Instantiates a new recorder, in case of compressed recording the parameters can be left as * 0. In case of errors, no exception is thrown, but the state is set to ERROR */ public MediaRecorderWrapper() { try { mRecorder = new MediaRecorder(); mRecorder.setAudioEncodingBitRate(24000); mRecorder.setAudioChannels(1); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); fPath = null; state = State.INITIALIZING; } catch (Exception e) { if (e.getMessage() != null) { SurespotLog.e(MediaRecorderWrapper.class.getName(), e, e.getMessage()); } else { SurespotLog.e( MediaRecorderWrapper.class.getName(), e, "Unknown error occured while initializing recording"); } state = State.ERROR; } }
/** * 开始录音 * * @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; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_record); chronometer = (Chronometer) findViewById(R.id.chrono); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); int fileformat = Integer.parseInt(sharedPref.getString(SettingsActivity.KEY_FILE_FORMAT, "")); int codec = Integer.parseInt(sharedPref.getString(SettingsActivity.KEY_CODEC, "")); // Setting up chart setupTopChart(); final String TAG = "test"; mLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout); mLayout.setTouchEnabled(false); mLayout.setMinFlingVelocity(100); mLayout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN); mLayout.setPanelHeight(600); ((TextView) findViewById(R.id.codec)) .setText(sharedPref.getString(SettingsActivity.KEY_CODEC, "")); myAudioRecorder = new MediaRecorder(); myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); myAudioRecorder.setOutputFormat(fileformat); myAudioRecorder.setAudioEncoder(codec); myAudioRecorder.setAudioEncodingBitRate(100000); FloatingActionButton mic = (FloatingActionButton) findViewById(R.id.record); mic.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#ffffff"))); mic.setRippleColor(getResources().getColor(R.color.colorAccent)); (findViewById(R.id.pause_record)) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (!drawDisplayed) { mLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); (findViewById(R.id.pause_record)) .animate() .rotationBy(180) .setDuration(400) .setInterpolator(new AccelerateDecelerateInterpolator()) .start(); drawDisplayed = true; } else { mLayout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN); (findViewById(R.id.pause_record)) .animate() .rotationBy(180) .setInterpolator(new AccelerateDecelerateInterpolator()) .setDuration(400) .start(); drawDisplayed = false; } } }); // Spinner spinner = (Spinner) findViewById(R.id.fileTypeSpinner); // Create an ArrayAdapter using the string array and a default spinner layout // ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, // R.array.filetypes, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears // adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner // spinner.setAdapter(adapter); (findViewById(R.id.stop_record)) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { stopRecording(v); } }); final LinearLayout bottomBar = (LinearLayout) findViewById(R.id.bottomBar); mic.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { stopRecording(v); } }); }
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; }