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; }
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; }
@Override protected Void doInBackground(MediaRecorder... params) { /*开始录音*/ MediaRecorder tmpMediaRecorder = params[0]; tmpMediaRecorder.start(); tmpMediaRecorder.setOnInfoListener( new OnInfoListener() { @Override public void onInfo(MediaRecorder mr, int what, int extra) { // TODO Auto-generated method stub if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { isMonitorRun = false; } } }); /*开始监控*/ isMonitorRun = true; while (isMonitorRun) { int sVolumeValue = tmpMediaRecorder.getMaxAmplitude(); if (sVolumeValue > 0) { mVolumeSize = 1000 * sVolumeValue / 32768; mHandler.postAtTime( new Runnable() { @Override public void run() { // TODO Auto-generated method stub mViewVolume.setText(mVolumeSize + ""); } }, 500); } } /*停止录音*/ tmpMediaRecorder.stop(); tmpMediaRecorder.release(); tmpMediaRecorder = null; mCountDownTimer.cancel(); // 停止计时 return null; }
@Override public void recordVideo(CameraSession session, VideoTransaction xact) throws Exception { Descriptor descriptor = (Descriptor) session.getDescriptor(); Camera camera = descriptor.getCamera(); if (camera != null) { camera.stopPreview(); camera.unlock(); try { recorder = new MediaRecorder(); recorder.setCamera(camera); recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); int cameraId = descriptor.getCameraId(); boolean canGoHigh = CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH); boolean canGoLow = CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW); if (canGoHigh && (xact.getQuality() == 1 || !canGoLow)) { recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH)); } else if (canGoLow) { recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW)); } else { throw new IllegalStateException("cannot find valid CamcorderProfile"); } recorder.setOutputFile(xact.getOutputPath().getAbsolutePath()); recorder.setMaxFileSize(xact.getSizeLimit()); recorder.setMaxDuration(xact.getDurationLimit()); recorder.setOnInfoListener(this); // recorder.setOrientationHint(...); recorder.prepare(); recorder.start(); this.xact = xact; } catch (IOException e) { recorder.release(); recorder = null; throw e; } } }
private void start() { try { if (!sdcardExit) { Toast.makeText(mContext, "请插入SD card", Toast.LENGTH_LONG).show(); return; } String mMinute1 = getTime(); myRecAudioFile = new File(myRecAudioDir, mMinute1 + SUFFIX); mMediaRecorder = new MediaRecorder(); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setOutputFormat(OutputFormat.RAW_AMR); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); if (!myRecAudioFile.exists()) { try { myRecAudioFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } mMediaRecorder.setOutputFile(myRecAudioFile.getAbsolutePath()); mMediaRecorder.prepare(); mMediaRecorder.start(); handler.post(mUpdateMicStatusTimer); mMediaRecorder.setOnInfoListener( new OnInfoListener() { @Override public void onInfo(MediaRecorder mr, int what, int extra) { int m = mr.getMaxAmplitude(); } }); } catch (IOException e) { e.printStackTrace(); } }