我正在尝试使用Google Glass MIC录制音频,但我不断收到 W / IMediaDeathNotifier:媒体服务器已死错误。想法?
它应该在第一次触摸时开始录制并在第二次触摸时停止,但第一次点击时会发生错误。
package com.google.android.glass.sample.charades;
import android.media.MediaRecorder;
import java.io.IOException;
import android.util.Log;
import android.os.Environment;
public class SlideshowActivity extends Activity {
private static final String LOG_TAG = "AudioRecordTest";
private MediaRecorder mRecorder = null;
private static String mFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/audiorecordtest.3gp";
private boolean recording = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slideshow);
mGestureDetector = new GestureDetector(this).setBaseListener(mBaseListener);
}
private void startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
Log.e(LOG_TAG, "File name: " + mFileName);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();
}
private void stopRecording() {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
private void onRecord(boolean start) {
if (start) {
startRecording();
} else {
stopRecording();
}
}
}
日志:
4242-4242 / com.google.android.glass.sample.charades E / AudioRecordTest:文件名:/storage/emulated/0/audiorecordtest.3gp
4242-4255 / com.google.android.glass.sample.charades W / IMediaDeathNotifier:媒体服务器已经死亡
我还在 AndroidManifest.xml 文件中添加了以下权限:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
答案 0 :(得分:5)
尝试拨打setPreviewDisplay
,在任何地方都没有注明,但有些人说预览用作存储视频文件的来源。
答案 1 :(得分:0)
我在录音中类似于此。
修复:更改格式记录器
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
更改示例:
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);