录音及播放的方法如下:

package com.example.audiorecord;

import java.io.File;
import java.io.IOException; import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class RecordActivity extends Activity { private static final String LOG_TAG = "AudioRecordTest";
// 语音文件保存路径
private String FileName = null; // 界面控件
private Button startRecord;
private Button startPlay;
private Button stopRecord;
private Button stopPlay; // 语音操作对象
private MediaPlayer mPlayer = null;
private MediaRecorder mRecorder = null; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // 开始录音
startRecord = (Button) findViewById(R.id.startRecord);
startRecord.setText(R.string.startRecord);
// 绑定监听器
startRecord.setOnClickListener(new startRecordListener()); // 结束录音
stopRecord = (Button) findViewById(R.id.stopRecord);
stopRecord.setText(R.string.stopRecord);
stopRecord.setOnClickListener(new stopRecordListener()); // 开始播放
startPlay = (Button) findViewById(R.id.startPlay);
startPlay.setText(R.string.startPlay);
// 绑定监听器
startPlay.setOnClickListener(new startPlayListener()); // 结束播放
stopPlay = (Button) findViewById(R.id.stopPlay);
stopPlay.setText(R.string.stopPlay);
stopPlay.setOnClickListener(new stopPlayListener()); // 设置sdcard的路径
FileName = Environment.getExternalStorageDirectory().getAbsolutePath();
FileName = FileName + File.separator + "audiorecordtest.arm";
} // 开始录音
class startRecordListener implements OnClickListener { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mRecorder.setOutputFile(FileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();
} } // 停止录音
class stopRecordListener implements OnClickListener { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
mRecorder.stop();
mRecorder.release();
mRecorder = null;
} } // 播放录音
class startPlayListener implements OnClickListener { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(FileName);
mPlayer.prepare();
mPlayer.start();
} catch (IOException e) {
Log.e(LOG_TAG, "播放失败");
}
} } // 停止播放录音
class stopPlayListener implements OnClickListener { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
mPlayer.release();
mPlayer = null;
} }
}

界面布局如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_name" /> <Button
android:id="@+id/startRecord"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <Button
android:id="@+id/stopRecord"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <Button
android:id="@+id/startPlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <Button
android:id="@+id/stopPlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> </LinearLayout>

完整项目代码: http://download.csdn.net/detail/abc13939746593/6920293

Android平台下实现录音及播放录音功能的简介的更多相关文章

  1. 【转】Android平台下利用zxing实现二维码开发

    http://www.cnblogs.com/dolphin0520/p/3355728.html 现在走在大街小巷都能看到二维码,而且最近由于项目需要,所以研究了下二维码开发的东西,开源的二维码扫描 ...

  2. 【转】Android 平台下使用 i2c-tools

    原文网址:http://my.oschina.net/luoly/blog/368881 Android 平台下使用 i2c-tools Andorid 开发板为 Freescale imx6 的 S ...

  3. Android平台下利用zxing实现二维码开发

    Android平台下利用zxing实现二维码开发 现在走在大街小巷都能看到二维码,而且最近由于项目需要,所以研究了下二维码开发的东西,开源的二维码扫描库主要有zxing和zbar,zbar在iPos平 ...

  4. 在Android平台下搭建PhoneGap开发环境--用HTML5开发游戏

    一.在Android平台下搭建PhoneGap开发环境具体怎么搭建我这里就不详细说了,如有需要我后面再讲 . PhoneGap 官方地址有详细说明:http://www.phonegap.com. 在 ...

  5. Android平台下渗透测试工具大集合

    Android平台下渗透测试工具大集合 分享一个google的项目,各种Android下的渗透测试工具. Ad Network Detector (1.2): http://market.androi ...

  6. (转)android平台下使用点九PNG技术

    “点九”是andriod平台的应用软件开发里的一种特殊的图片形式,文件扩展名为:.9.png 智能手机中有自动横屏的功能,同一幅界面会在随着手机(或平板电脑)中的方向传感器的参数不同而改变显示的方向, ...

  7. (转载)Android平台下利用zxing实现二维码开发

    Android平台下利用zxing实现二维码开发 现在走在大街小巷都能看到二维码,而且最近由于项目需要,所以研究了下二维码开发的东西,开源的二维码扫描库主要有zxing和zbar,zbar在iPos平 ...

  8. Android平台的音乐资源管理与播放

    Android平台基于Linux和开放手机联盟(OHA)系统,经过中国移动的创新研发,设计出拥有新颖独特的用户操作界面,增强了浏览器能力和WAP 兼容性,优化了多媒体领域的OpenCORE.浏览器领域 ...

  9. Android平台下使用lua调用Java代码经验总结

    动态语言以其执行的灵活性,可配置性.方便调试能够为开发带来极大的方便.假设用好了.能够极大的提高开发的效率. 怪不得像游戏开发这样复杂的软件开发里没有不集成脚本语言的. 当中,lua以其小巧,灵活.方 ...

随机推荐

  1. Codeforces Round #363 (Div. 2)->A. Launch of Collider

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. Oracle调优总结(经典实践 重要)

    转载:http://langgufu.iteye.com/blog/1974211 Problem Description:1.每个表的结构及主键索引情况2.每个表的count(*)记录是多少3.对于 ...

  3. override equals in Java

    equals() (javadoc) must define an equality relation (it must be reflexive, symmetric, and transitive ...

  4. 可持久化trie 学习总结

    QAQ 以前一直觉得可持久化trie很难,今天强行写了一发觉得还是蛮简单的嘛 自己的模板是自己手写的,写了几道题目并没有出过错误 THUSC的第二题的解法五貌似就是可持久化trie,时间复杂度O(60 ...

  5. lintcode:Plus One 加一

    题目: 加一 给定一个非负数,表示一个数字数组,在该数的基础上+1,返回一个新的数组. 该数字按照大小进行排列,最大的数在列表的最前面. 样例 给定 [1,2,3] 表示 123, 返回 [1,2,4 ...

  6. parent children

    class parent{ protected static int count=0; public parent() { count++; } } public class child extend ...

  7. FastDFS_v5.05安装配置

    废话不多讲,启动FastDFS文件服务器的命令是 #/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf #/usr/bin/fdfs_storaged /etc ...

  8. MATLAB曲线绘制

    一. 二维数据曲线图1.1 绘制 单根二维曲线plot 函数的基本调用 格式为:plot(x,y) 其中x和y为长度相同的向量,分别用于存储x坐标 和y坐标数据. 例1-1 在0≤x≤2p区间内,绘制 ...

  9. powerdesigner连接数据库 导出数据 生成PDM文件 傻瓜试教程

    也可下载文档:http://download.csdn.net/detail/shutingwang/6378665 

  10. 尝鲜delphi开发android/ios_环境搭建

    Delphi这又老树发新枝了,开始做终端程序开发了,这个东西的准确名字是:RAD Studio XE5,可以使用delphi和c++ builder进行终端开发. 我尽可能讲啰嗦一些,免得回头被人问. ...