【问题标题】:Android: Pause voice Recorder and ResumeAndroid:暂停录音机和恢复
【发布时间】:2013-08-11 01:54:59
【问题描述】:

我使用以下代码作为基础来创建记录器。我可以开始和停止录音,它会正确保存在该位置。但是现在我有暂停录音机的要求

如何暂停录音机?并恢复录音?我在我的三星 Galaxy Ace 中看到了一个录音应用程序,它有一个暂停按钮。

谁能赐教。

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() {

      }

    }

【问题讨论】:

    标签: android media recorder


    【解决方案1】:

    看看这两页

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

    根据第一篇文章有​​一个 pause()

    但我在第二个链接上没有看到 pause() 方法,所以我不确定

    第一篇文章引用的另一件事: “但是,当您调用 stop() 时,请注意,在您再次准备 MediaPlayer 之前,您不能再次调用 start()。 在编写与 MediaPlayer 对象交互的代码时,请始终牢记状态图,因为从错误状态调用其方法是导致错误的常见原因。”

    所以也许你可以停止()准备媒体播放器然后再次启动()

    【讨论】:

    • 正如你所说的暂停对 MediaPlayer 不是录音机可用。这就是我现在遇到这个问题的地方:(
    • 我不想说任何不可能的事情,但这里有另一个关于同一件事的 stackoverflow 帖子 - stackoverflow.com/questions/6128440/…
    • 这是原生 API 中缺少的一个真正烦人的功能 :(
    • 任何投票的机会。我确实回答了这个问题:D 很遗憾听到这个消息,希望在下一个版本中(哦,这是软件的常用短语)
    猜你喜欢
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-21
    相关资源
    最近更新 更多