2 a283398689 a283398689 于 2014.09.28 11:01 提问

安卓录像问题。报错Media server died.

public class MainActivity extends Activity {

MediaRecorder  recorder= null;
Button startButton = null; 
Button endtButton = null; 
SurfaceView  face = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    startButton=(Button) findViewById(R.id.end);
    endtButton= (Button) findViewById(R.id.start);
    face=                 (SurfaceView) findViewById(R.id.surfaceView);
    face.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    face.getHolder().setFixedSize(176, 144);
    face.getHolder().setKeepScreenOn(true);
    startButton.setOnClickListener(ButtonClickDo);
    endtButton.setOnClickListener(ButtonClickDo);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}



public void startRecord() throws Throwable, IOException{
    File f = new File( Environment.getExternalStorageDirectory() ,System.currentTimeMillis()+".3gp");
  recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setVideoSize(320, 240);
    recorder.setVideoFrameRate(5);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
    recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    recorder.setOutputFile(f.getAbsolutePath());
recorder.setPreviewDisplay(face.getHolder().getSurface());
System.out.println("路径"+    f.getAbsolutePath());
    recorder.prepare();
    recorder.start();


}



public void stopRecord(){
    if(recorder!=null){
        recorder.stop();
        recorder.release();
        recorder=null;
    }

}

private OnClickListener    ButtonClickDo = new OnClickListener() {
    @Override
    public void onClick(View v) {
         Integer id =   v.getId();
         System.out.println("id为:"+ id +"结果" +(endtButton.getId()==id));
         if(endtButton.getId()==id){
                try {
                    startRecord();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (Throwable e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
         }
            else{
             stopRecord();
         }



    }
};

}

这段代码可以正常的录像, 发到手机内存里 。但是我把
recorder.setPreviewDisplay(face.getHolder().getSurface()); 这句话给注释掉就报
Media server died. 。拍出来的东西只有23KB 怎么拍都只有23KB 不能播放 说文件损坏,
请问是怎么回事。 我想达到 录像 但不显示录像的画面。 怎么操作

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!