Android按下录音录音动画效果 ,自定义View
先看效果图
录音
private void playSound() { mMediaRecorder = new MediaRecorder(); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); // 设置音频的格式 mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // 设置音频的编码为amr mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mMediaRecorder.setAudioSamplingRate(8000); mMediaRecorder.setOutputFile(mCurrentFilePath); try { mMediaRecorder.prepare(); mMediaRecorder.start(); } catch (IOException e) { e.printStackTrace(); } handler.sendEmptyMessageDelayed(SOUND_WHAT, 150); } private void stopSound() { if (mMediaRecorder != null) { mMediaRecorder.stop(); mMediaRecorder.release(); mMediaRecorder = null; if (handler != null) handler.removeCallbacksAndMessages(null); } }
/** * 画背景刻度 * @param canvas */ private void drawBackgroundScale(Canvas canvas){ int p = maxColorNumber; float start = -90f; paint.setShader(null); for (int i = 0; i < p; i++) { canvas.drawArc(oval, start + singlPoint - lineWidth, lineWidth, false, paint); // 绘制间隔快 start = (start + singlPoint); } } /** * 画进度刻度 * @param canvas */ private void drawScale(Canvas canvas){ canvas.save(); int p = (int) (mProgress / 100f * maxColorNumber); float start = -90f; for (int i = 0;i<p ;i++){ paint.setShader(sweepGradient); canvas.drawArc(oval, start + singlPoint - lineWidth, lineWidth, false, paint); // 绘制间隔快 start = (start + singlPoint); } canvas.restore(); }