录音机录制声音

1、定义

/* 录制的音频文件 */
private File mRecAudioFile;
private File mRecAudioPath;
/* MediaRecorder对象 */
private MediaRecorder mMediaRecorder;
/* 录音文件列表 */
private List<String> mMusicList = new ArrayList<String>();
/* 零时文件的前缀 */
private String strTempFile = "recaudio_";

2、

/* 检测是否存在SD卡 */
if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
{
/* 得到SD卡得路径 */
mRecAudioPath = Environment.getExternalStorageDirectory();
/* 更新所有录音文件到List中 */
}

3、录音

/* 创建录音文件 */
mRecAudioFile = File.createTempFile(strTempFile, ".amr", mRecAudioPath);
/* 实例化MediaRecorder对象 */
mMediaRecorder = new MediaRecorder();
/* 设置麦克风 */
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
/* 设置输出文件的格式 */
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
/* 设置音频文件的编码 */
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
/* 设置输出文件的路径 */
mMediaRecorder.setOutputFile(mRecAudioFile.getAbsolutePath());
/* 准备 */
mMediaRecorder.prepare();
/* 开始 */
mMediaRecorder.start();

4、停止


/* 停止录音 */
mMediaRecorder.stop();

 

5、

/* 播放录音文件 */
private void playMusic(File file)
{
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
/* 设置文件类型 */
intent.setDataAndType(Uri.fromFile(file), "audio");
startActivity(intent);
}

转载于:https://www.cnblogs.com/wdc224/p/3744112.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值