@Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: Debug.d(TAG, "ACTION_DOWN", DEBUG); break; case MotionEvent.ACTION_UP: Debug.d(TAG, "ACTION_UP stop record", DEBUG); stopRecording(); break; } return false; }
/** * 播放录音 * * @author shicong */ private void startPlaying(File aFile) { mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(aFile.getAbsolutePath()); mPlayer.prepare(); mPlayer.start(); } catch (IOException e) { Debug.d(TAG, "prepare() failed", DEBUG); } }
@Override public boolean onLongClick(View v) { // TODO Auto-generated method stub Debug.d(TAG, "onLongClick start to record...", DEBUG); /*重新录音时,删除已有的录音文件*/ if (mAudioFile != null) { mAudioFile.delete(); } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); mAudioFile = new File(Environment.getExternalStorageDirectory() + "/Phamily", timeStamp + ".amr"); startRecording(mAudioFile); return true; }
/** * 录音 * * @author shicong */ private void startRecording(File aFile) { MediaRecorder sRecorder = new MediaRecorder(); sRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); sRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); sRecorder.setOutputFile(aFile.getAbsolutePath()); sRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); sRecorder.setMaxDuration(mRecord_Max_Time); try { sRecorder.prepare(); } catch (IOException e) { Debug.d(TAG, "Start record error...", DEBUG); UtilSystem.SystemToast(mContext, "录音失败!~~"); return; } /*数据监控*/ mVolumeMonitorTask = new VolumeMonitor(); mVolumeMonitorTask.execute(sRecorder); }
@Override public void onClick(View v) { // TODO Auto-generated method stub Debug.d(TAG, "onClick start to record but time is so short...", DEBUG); UtilSystem.SystemToast(mContext, "时间太短了哦~~~"); }