我正在为 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;
}
}
};
我可能已经接近答案了,但我只需要一些指导,也许我在某个地方出了问题?任何帮助就足够了。提前致谢