Capture a video and store it at a specific location rather than a default location

后端 未结 3 1961
长发绾君心
长发绾君心 2021-01-03 14:07

I want to capture video and store video at specific location other than default location.

I know there is a method with MediaStore called setOutPutFile(\"Strin

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 14:19

    I wasn't happy with any of the solutions provided here. Here's an extremely simple solution that will save the video in folder of your choice.

    private static final int REQUEST_VIDEO_CAPTURE = 300;
    private Uri videoUri;
    
    private void dispatchVideoIntent(){
        Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        File outputFile = new File("your file path goes here");
        videoUri = Uri.fromFile(outputFile);
        takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
        if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
        }
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK && videoUri != null) {
                // do what you want with videoUri
        }
    }
    

提交回复
热议问题