如何使用自定义媒体录音机进行录音?
我正在为 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;
}
}
};
我可能已经接近答案了,但我只需要一些指导,也许我在某个地方出了问题?任何帮助就足够了。提前致谢
I am creating an app for android 2.1 - 2.3 phones and I need to know how to record a video and implement flash lighting when the video is being recorded. I have seen the following sample code below from various websites, and it works on 2.1 but anything higher and the preview screen remains dark.
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();
}
When I click on this button below, the recording starts, but before that the screen is black and doesn't show a preview.
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;
}
}
};
I am probably close to the answer, but I just need some guidance perhaps i am putting something wrong somewhere? Any help will suffice. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的prepareRecorder()方法上,在调用prepare()之前也添加这一行;
On your prepareRecorder() method add this line too before calling prepare();