糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > Android仿微信语音录制和播放

Android仿微信语音录制和播放

时间:2020-10-17 22:14:48

相关推荐

Android仿微信语音录制和播放

介绍

这是一款参考环信的语音录制和播放库,轻量级,自带语音录制时动画效果,根据声音大小进行动画展示:

具体看图和gif动画效果:

使用步骤:

注意,目前还在开发阶段,有bug记得提issues哈

注意,6.0以上系统需要运行时授权读取sd卡和音频

1.添加Jcenter仓库 Gradle依赖:

compile 'com.ilike:voicerecorder:1.0.0'

或者

Maven

<dependency><groupId>com.ilike</groupId><artifactId>voicerecorder</artifactId><version>1.0.0</version><type>pom</type></dependency>

2.在Activity中添加如下代码:

/*** 设置文件存放目录,存放路径如:/Android/data/包名/chat/voice/* 默认不设置,路径存放为:/Android/data/包名/chat/voice/*/PathUtil.getInstance().createDirs("chat", "voice", appContext);

/*** 自定义命名文件* 默认不设置是用时间戳*/voiceRecorderView.setCustomNamingFile(true,"语音命名.mp3");

/*** 自定义语音录制过程中,声音大小的动画,默认使用库文件中的动画,* 目前默认需要设置15张图片,以后更新自定义动画帧数*/voiceRecorderView.setDrawableAnimation(Drawable[] animationDrawable)

/*** 设置停止播放语音时,显示的静态icon*/VoicePlayClickListener.setStopPlayIcon(R.drawable.ease_chatto_voice_playing)

/*** 设置播放语音的帧动画,*/VoicePlayClickListener.setPlayingIconDrawableResoure(R.drawable.voice_to_icon)-------------------------------------------------------比如这样的动画:<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="/apk/res/android"android:oneshot="false"><itemandroid:drawable="@drawable/ease_chatto_voice_playing_f1"android:duration="200" /><itemandroid:drawable="@drawable/ease_chatto_voice_playing_f2"android:duration="200" /><itemandroid:drawable="@drawable/ease_chatto_voice_playing_f3"android:duration="200" /></animation-list>-------------------------------------------------------

/*** 录制语音*/tvRecorder.setOnTouchListener(new View.OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {return voiceRecorderView.onPressToSpeakBtnTouch(v, event, new VoiceRecorderView.EaseVoiceRecorderCallback() {@Overridepublic void onVoiceRecordComplete(String voiceFilePath, int voiceTimeLength) {Log.e("voiceFilePath=", voiceFilePath + " time = " + voiceTimeLength);/***voiceFilePath 为录音文件存放在sd的路径* voiceTimeLength 录音文件的时长*/}});}});

/*** 播放SD卡本地语音路径* imageView显示动画* Context,上下文* path ,语音路径*/new VoicePlayClickListener(imageView, Context).playVoice(path);/*** 播放网络语音路径* imageView显示动画* Context,上下文* path ,语音路径*/new VoicePlayClickListener(imageView, Context).playUrlVoice(path);

3.在布局文件xml中添加如下:

“`xml

<com.ilike.voicerecorder.widget.VoiceRecorderViewandroid:id="@+id/voice_recorder"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:visibility="invisible" />

“`

喜欢记得start一下哈

/wangshanhai/VoiceRecorder

如果觉得《Android仿微信语音录制和播放》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。