鑑於項目須要,封裝了一個錄音和播放的管理類,分享出來給你們,有須要的直接拿去用!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