Android仿微信、录制音频并发送功能

本文介绍了如何在Android应用中实现仿微信的录音功能,包括自定义录音Button的三种状态(正常、录音、取消)、录音对话框的布局、录音管理类AudioManager的创建、ListView的适配器及媒体播放管理类MediaManager的实现,以及所需的权限添加。通过这些步骤,可以完成从录音到播放的完整功能。
摘要由CSDN通过智能技术生成
这篇文章主要介绍了Android仿微信、录制音频并发送功能的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

MyRecorder(仿微信,录制音频并发送功能)

①布局实现(activity_main.xml) 
布局采用线性布局,上面使用的一个ListView,下面使用的是一个自定义的Button(会在下面进行介绍)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 tools:context="com.yitong.myrecorder.MainActivity">

 <ListView
  android:id="@+id/main_listview"
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1"
  android:background="#ebebeb"
  android:dividerHeight="10dp"
  android:divider="@null"
  />
 <FrameLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#fff">
  <com.yitong.myrecorder.view.AudioRecorderButton
   android:id="@+id/main_btn"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:gravity="center"
   android:layout_marginTop="6dp"
   android:layout_marginBottom="6dp"
   android:layout_marginLeft="60dp"
   android:layout_marginRight="60dp"
   android:minHeight="0dp"
   android:padding="6dp"
   android:text="@string/str_recoder_normal"
   android:textSize="20sp"
   android:textColor="#727272"
   android:background="@drawable/btn_recorder_normal"
   />
  <View
   android:layout_width="match_parent"
   android:layout_height="1dp"
   android:background="#ccc"/>
 </FrameLayout>
</LinearLayout>

相关使用的string值(需要添加到value/string中):  

 <string name="str_recoder_normal">按住说话</string>
 <string name="str_recorder_recording">松开结束</string>
 <string name="str_recorder_want_cancel">松开手指,取消发送</string>
 <string name="str_dialog_want_cancel">手指上滑,取消发送</string>
 <string name="str_dialog_want_send">手指上滑,取消发送</string>
 <string name="str_dialog_time_short">录音时间过短</string>

②我们分析一下自定Button的几种状态: 
1.正常状态 (在初次显示,即没有点击的时候显示的状态,显示的文本为“按住说话”) 
2.录音状态 (当手指按在Button上时,即为录音状态,显示的文本为“松开结束”) 
3.取消状态 (当手指上滑,此时若松开手指,便取消发送,即为取消状态,显示的文本为“松开手指,取消发送”)

③当录音状态时,在View上有一个Dialog的提示,首先我们先自定义这个Dialog的布局:

<?xml version=
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值