0
我正在爲android 2.1 - 2.3手機創建一個應用程序,我需要知道如何記錄視頻並在錄製視頻時實施閃光照明。我在下面的例子中看到了來自各種網站的示例代碼,它可以在2.1版本上運行,但是任何更高的代碼,預覽屏幕仍然很暗。如何使用自定義媒體錄製器進行錄製?
boolean recording=false;
Camera camera = null;
Parameters parameters;
SurfaceView cameraView = (SurfaceView) findViewById(R.id.surface_view);
holder = cameraView.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.getSurface();
private void prepareRecorder()
{
Log.d("BROADCAST", "Camera not null");
recorder.setPreviewDisplay(holder.getSurface());
try{
recorder.prepare();
//implementing flash button below but fails as soon as recording begins when turned on
Button flash = (Button) findViewById (R.id.flash);
flash.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(camera == null){
camera = Camera.open();
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
}else{
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
camera.release();
camera = null;
}
}});
} catch (IllegalStateException e) {
e.printStackTrace();
finish();
} catch (IOException e) {
e.printStackTrace();
finish();
}
}
public void surfaceCreated(SurfaceHolder holder)
{
prepareRecorder();
Log.v(TAG,"surfaceCreated");
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {}
public void surfaceDestroyed(SurfaceHolder holder)
{
recorder.release();
}
當我點擊下面的這個按鈕,開始錄製,但在此之前屏幕是黑色的,並且不顯示預覽。
private Button.OnClickListener myButtonOnClickListener = new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (recording) {
recorder.stop();
recorder.release();// stops the recording process
startActivity(new Intent(""));
finish();
}
else {
recorder.start();
counter.start();
recording = true;
}
}
};
我可能接近答案,但我只是需要一些指導,也許我在某處放錯了什麼?任何幫助就足夠了。提前致謝