W/IMediaDeathNotifier﹕ media server died

2019-03-02 19:27发布

问题:

I'm trying to record audio using Google Glass MIC but I keep getting W/IMediaDeathNotifier﹕ media server died error. Thoughts?

It should start recording on the first touch and stops on the second touch, but the error happens on the first click.

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

}

Log:

4242-4242/com.google.android.glass.sample.charades E/AudioRecordTest﹕ File name: /storage/emulated/0/audiorecordtest.3gp

4242-4255/com.google.android.glass.sample.charades W/IMediaDeathNotifier﹕ media server died

I've also added the following permission on the AndroidManifest.xml file:

<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" />

回答1:

Try calling setPreviewDisplay, it isn't noted anywhere but some people say the preview is used as source to store the video file.

http://developer.android.com/reference/android/media/MediaRecorder.html#setPreviewDisplay(android.view.Surface)



回答2:

I similar this on audio record.

Fix: change format recorder

mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

Change example:

mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);