In view of the project needs, encapsulated a recording and playback of the management class, share out to everyone, there is a need to take directly to use!

There is a picture and there is a truth:

Functions:

  • Realize recording function, provide pause, continue to switch, and monitor the volume size to wavy lines appear
  • Play function, play frame animation

Usage 1. Record

VoiceManage mVoiceManage =VoiceManager.getInstance(mContext);

  mVoiceManage.pauseOrStartVoiceRecord();// Pause or continue

  mVoiceManage.stopVoiceRecord();// Complete the recording

  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); }}});Copy the code

2. Play

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());Copy the code

Finally, the sample source code is attached. Welcome to fork and Star

More exciting articles please pay attention to the wechat public number “Android experience sharing “: here will be a long-term experience for you to share Android master, Chinese and foreign open source projects, source code analysis, framework design and Android good article recommendation!

Scan and add me