鉴于项目须要,封装了一个录音和播放的管理类,分享出来给你们,有须要的直接拿去用!javascript
有图有真相:
java
实现功能:git
用法
1.录音 github
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好文推荐!
ide