安卓:使用记录默认录像机,并返回SD卡路径 [英] Android: Record using default video recorder and return the sd card path
问题描述
我试图开发一种使用记录默认应用程序的视频,并写入到SD卡上,然后返回SD卡路径previous活动的应用程序。为什么它不是为我工作?我得到取消所有敬酒的时候,我在相机点击后退按钮。
公共类AndroidVideoActivity延伸活动{
最终静态INT REQUEST_VIDEO_CAPTURED = 1;
乌里uriVideo = NULL; / **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main); 按钮btnVideoRecorder =(按钮)findViewById(R.id.buttonClick);
btnVideoRecorder.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v){
意向意图=新意图(android.media.action.VIDEO_CAMERA);
startActivityForResult(意向,REQUEST_VIDEO_CAPTURED);
}
}); } @覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
// TODO自动生成方法存根
如果(结果code == RESULT_OK){
如果(要求code == REQUEST_VIDEO_CAPTURED){
uriVideo = data.getData();
Toast.makeText(AndroidVideoActivity.this,uriVideo.getPath(),
Toast.LENGTH_LONG).show();
}
}否则如果(结果code == RESULT_CANCELED){
uriVideo = NULL;
Toast.makeText(AndroidVideoActivity.this,已取消!
Toast.LENGTH_LONG).show();
} }
}
您不应该打到后退按钮 - 后退按钮=取消。您应该能够录制视频,而当你停止录制,您应该preSS完成或类似的东西(我只用摄像头,视频不这样做),然后它会自动返回到您的应用程序
I'm trying to develop an application which records the video using default application and writes to sd card and then return the sd card path to previous activity. Why it is not working for me?? i'm getting cancelled toast all the time when I click back button in the camera.
public class AndroidVideoActivity extends Activity {
final static int REQUEST_VIDEO_CAPTURED = 1;
Uri uriVideo = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnVideoRecorder = (Button) findViewById(R.id.buttonClick);
btnVideoRecorder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("android.media.action.VIDEO_CAMERA");
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_VIDEO_CAPTURED) {
uriVideo = data.getData();
Toast.makeText(AndroidVideoActivity.this, uriVideo.getPath(),
Toast.LENGTH_LONG).show();
}
} else if (resultCode == RESULT_CANCELED) {
uriVideo = null;
Toast.makeText(AndroidVideoActivity.this, "Cancelled!",
Toast.LENGTH_LONG).show();
}
}
}
You shouldn't have to hit the back button - the back button = cancel. You should be able to record the video, and when you stop recording, you should press 'Done' or something similar (I've only done this with camera, not video), and then it will return to your app automatically.
这篇关于安卓:使用记录默认录像机,并返回SD卡路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!