录音和播放,轻量到只有一个管理类

鉴于项目需要,封装了一个录音和播放的管理类,分享出来给大家,有需要的直接拿去用!

有图有真相:

录音和播放,轻量到只有一个管理类_第1张图片

实现功能:

  • 实现录音功能,提供暂停、继续切换,并且监听音量大小以波浪线呈现出现
  • 实现播放功能,播放实现帧动画

用法
1.录音

VoiceManage mVoiceManage =VoiceManager.getInstance(mContext);

mVoiceManage.pauseOrStartVoiceRecord();//暂停或继续

mVoiceManage.stopVoiceRecord();//完成录音

mVoiceManage.setVoiceRecordListener(new VoiceManager.VoiceRecordCallBack() {
      @Override
      public void recDoing(long time, String strTime) {
          mRecordHintTv.setText(strTime);
      }

      @Override
      public void recVoiceGrade(int grade) {
          voicLine.setVolume(grade);
      }

      @Override
      public void recStart(boolean init) {
          mIvPauseContinue.setImageResource(R.drawable.icon_pause);
          voicLine.setContinue();
      }

      @Override
      public void recPause(String str) {
          mIvPauseContinue.setImageResource(R.drawable.icon_continue);
          voicLine.setPause();
      }


      @Override
      public void recFinish(long length, String strLength, String path) {
          if (enRecordVoiceListener != null) {
              enRecordVoiceListener.onFinishRecord(length, strLength, path);
          }
      }
  });

2.播放

VoiceManage mVoiceManage  =VoiceManager.getInstance(mContext);
mVoiceManage.setVoicePlayListener(new VoiceManager.VoicePlayCallBack() {
                    @Override
                    public void voiceTotalLength(long time, String strTime) {

                    }

                    @Override
                    public void playDoing(long time, String strTime) {


                    }

                    @Override
                    public void playPause() {

                    }

                    @Override
                    public void playStart() {

                    }

                    @Override
                    public void playFinish() {
                        if (voiceAnimation != null) {
                            voiceAnimation.stop();
                            voiceAnimation.selectDrawable(0);
                        }
                    }
                });
    mVoiceManage.startPlay(voice.getFilePath());

最后附上示例源码,欢迎fork and star

更多精彩文章请关注微信公众号"Android经验分享":这里将长期为您分享Android高手经验、中外开源项目、源码解析、框架设计和Android好文推荐!

录音和播放,轻量到只有一个管理类_第2张图片
扫一扫加我哦

你可能感兴趣的:(录音和播放,轻量到只有一个管理类)