我使用以下代码作为基础来创建记录器。我可以开始和停止录音,并且它会正确保存在该位置。但现在我有一个要求暂停录音机
如何暂停录音机?并恢复录音?我在我的三星 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() {
}
}
查看这两页
http://developer.android.com/guide/topics/media/index.html http://developer.android.com/guide/topics/media/index.htmlhttp://developer.android.com/reference/android/media/MediaRecorder.html
根据第一篇文章有一个暂停()
但我在第二个链接上没有看到暂停()方法,所以我不确定
第一篇文章引用的另一件事:
“但是,当您调用 stop() 时,请注意,在再次准备 MediaPlayer 之前,您无法再次调用 start()。
在编写与 MediaPlayer 对象交互的代码时,请始终牢记状态图,因为从错误的状态调用其方法是导致错误的常见原因。”
所以也许你可以停止()准备媒体播放器然后再次启动()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)