我想启动相机并通过单击Android中的应用程序自动开始录制。我有启动相机的代码,但我不知道如何开始自动捕获视频。请帮忙。 启动相机的代码 -
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c1_main);
Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
StartActivityForResult(intent,CAPTURE_VIDEO_ACTIVITY);
}
我发现了view.performclick但不知道如何使用相机
答案 0 :(得分:1)
好的,请在代码中进行以下更改。
Button play;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c1_main);
play = findViewById ( R.id.btnPlay ); // assuming you have this button in your .xml file.
play.setOnClickListener ( new OnClickListener()
{
@Override
public void onClick ( View view )
{
Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
StartActivityForResult(intent,CAPTURE_VIDEO_ACTIVITY);
}
});
}
答案 1 :(得分:1)
使用MediaRecorder实现此目的。虽然它需要更多的工作,但会给你更多的控制。请点击此链接http://android-er.blogspot.tw/2011/04/start-video-recording-using.html。由于您不需要任何按钮点击进行录制,因此请在启动相机前保持延迟。这样做
myButton.setPressed(true); //you won't click the button
myButton.invalidate();
myButton.postDelayed(new Runnable() {
public void run() {
myButton.setPressed(false);
myButton.invalidate();
releaseCamera(); //release camera from preview before MediaRecorder starts
if(!prepareMediaRecorder()){
Toast.makeText(AndroidVideoCapture.this,"could not prepare MediaRecorder",Toast.LENGTH_LONG).show();
finish();
}
mediaRecorder.start();
}
},5000); //causes delay of 5 seconds befor recording starts