zoukankan      html  css  js  c++  java
  • 录音机录制声音

    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);
    }

  • 相关阅读:
    不知如何摧毁Kendo UI for jQuery小部件?这份指南不得不看
    MyEclipse导航代码第二弹,Java开发更便捷
    索引扫描与索引查找区别
    Chrome使用技巧
    什么是中台?所有的中台都是业务中台
    跨域资源共享CORS详解
    多线程之入门起步(三)
    聊天程序——基于Socket、Thread (二)
    多线程的相关概念(一)
    使用BCP实用工具导出导入数据
  • 原文地址:https://www.cnblogs.com/wdc224/p/3744112.html
Copyright © 2011-2022 走看看