Android: Record using default video recorder and return the sd card path

流过昼夜 提交于 2019-12-13 00:27:24

问题


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();
        }

    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/6968449/android-record-using-default-video-recorder-and-return-the-sd-card-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!