安卓:暂停录音机和简历 [英] Android: Pause voice Recorder and Resume

查看:153
本文介绍了安卓:暂停录音机和简历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code为基础来创建一个记录。我可以启动和停止录音并获取位置正确保存。但现在我有一个质量要求暂停录音

如何暂停录音机?并继续录音?我见过我的三星Galaxy王牌语音录音appliation,它有一个暂停按钮。

有人可以告诉我。

 公共类音频{
     最后MediaRecorder记录=新MediaRecorder();
      最后弦乐路径;      / **
       *创建在给定的路径中的新录音(相对于SD卡的根目录)。
       * /
      公共音频(字符串路径){        this.path = sanitizePath(路径);
      }      私人字符串sanitizePath(字符串路径){
        如果(!path.startsWith(/)){
          路径=/+路径;
        }
        如果(!path.contains(。)){
          路径+ =.3GPP;
        }
        返回Environment.getExternalStorageDirectory()getAbsolutePath()+路径。
      }      / **
       *开始一个新的记录。
       * /
      公共无效的start()抛出IOException
        字符串状态= android.os.Environment.getExternalStorageState();
        如果(!state.equals(android.os.Environment.MEDIA_MOUNTED)){
            抛出新IOException异常(SD卡未安装它。+状态+。);
        }        //确保目录,我们计划存储在记录存在
        文件目录=新的文件(路径).getParentFile();
        如果(directory.exists()及!&放大器;!directory.mkdirs()){
          抛出新IOException异常(路径文件无法被创建。);
        }       尝试{
           recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
            recorder.setOutputFile(路径);            。录音机prepare();
            recorder.start();
    }赶上(例外五){
        e.printStackTrace();
        // TODO:处理异常
    }
      }      / **
       *停止了已经previously开始录音。
       * /
      公共无效停止()抛出IOException
        recorder.stop();
        recorder.reset();
        recorder.release();
      }      公共无效暂停(){      }    }


解决方案

看看这2页

http://developer.android.com/guide/topics/media/ index.html的
http://developer.android.com/reference/android/media/MediaRecorder.html

根据第一条有一个停顿()

但我不看到第二个链接一个暂停()方法,以便即时通讯不知道

另一件事是,第一篇文章引用:
当你调用stop(),但是,请注意,你不能说重新开始(),直到你prepare在MediaPlayer。
写code,与一个MediaPlayer对象进行交互时,因为调用从错误的状态,它的方法是错误的常见原因始终保持状态图记。

所以也许ü可以只停留()prepare媒体播放器再启动()再次

I've used following code as base to create a recorder. I can start and stop audio recording and it gets saved properly in the location. But now I have a requirments to pause the voice recorder

How to pause the audio recorder? And resume voice recording? I've seen a voice recording appliation in my samsung galaxy Ace, it has a pause button.

Can someone enlighten me.

public class audio {
     final MediaRecorder recorder = new MediaRecorder();
      final String path;

      /**
       * Creates a new audio recording at the given path (relative to root of SD card).
       */
      public audio(String path) {

        this.path = sanitizePath(path);
      }

      private String sanitizePath(String path) {
        if (!path.startsWith("/")) {
          path = "/" + path;
        }
        if (!path.contains(".")) {
          path += ".3gpp";
        }
        return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
      }

      /**
       * Starts a new recording.
       */
      public void start() throws IOException {
        String state = android.os.Environment.getExternalStorageState();
        if(!state.equals(android.os.Environment.MEDIA_MOUNTED))  {
            throw new IOException("SD Card is not mounted.  It is " + state + ".");
        }

        // make sure the directory we plan to store the recording in exists
        File directory = new File(path).getParentFile();
        if (!directory.exists() && !directory.mkdirs()) {
          throw new IOException("Path to file could not be created.");
        }

       try {
           recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            recorder.setOutputFile(path);

            recorder.prepare();
            recorder.start();
    } catch (Exception e) {
        e.printStackTrace();
        // TODO: handle exception
    }
      }

      /**
       * Stops a recording that has been previously started.
       */
      public void stop() throws IOException {
        recorder.stop();
        recorder.reset();
        recorder.release(); 
      }

      public void pause() {

      }

    }

解决方案

check out these 2 pages

http://developer.android.com/guide/topics/media/index.html http://developer.android.com/reference/android/media/MediaRecorder.html

according to the first article there is a pause()

but i dont see a pause() method on that second link so im not sure

the other thing that the first article references: "When you call stop(), however, notice that you cannot call start() again until you prepare the MediaPlayer again. Always keep the state diagram in mind when writing code that interacts with a MediaPlayer object, because calling its methods from the wrong state is a common cause of bugs."

so maybe u can just stop() prepare mediaplayer then start() again

这篇关于安卓:暂停录音机和简历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆