Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 设置自定义视频存储路径_Android - Fatal编程技术网

Android 设置自定义视频存储路径

Android 设置自定义视频存储路径,android,Android,我很难理解要更改代码的哪一部分来设置自定义文件存储路径。此活动成功启动android camera应用程序,允许您拍摄视频,然后返回活动,并说视频已保存至:“File:///storage/emulated/0/videoapp/examplevideoname.mp4" 我只想将它保存到我选择的另一个文件夹中,但这是谷歌教程中的内容,我无法确定需要更改的部分: 非常感谢所有的帮助!谷歌的代码甚至被注释以提供帮助,但我还是很新,对我来说还不清楚 很明显,“getExternalStorageP

我很难理解要更改代码的哪一部分来设置自定义文件存储路径。此活动成功启动android camera应用程序,允许您拍摄视频,然后返回活动,并说视频已保存至:“File:///storage/emulated/0/videoapp/examplevideoname.mp4"

我只想将它保存到我选择的另一个文件夹中,但这是谷歌教程中的内容,我无法确定需要更改的部分:

非常感谢所有的帮助!谷歌的代码甚至被注释以提供帮助,但我还是很新,对我来说还不清楚

很明显,“getExternalStoragePublicDirectory”与此有关,但我不知道是否应该用新路径或其他内容替换该部分

以下是代码片段:

一旦创建:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);

    //create new Intent
    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

    fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);  // create a file to save the video
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);  // set the image file name

    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high

    // start the Video Capture Intent
    startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
}
onActivityResult:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            // Video captured and saved to fileUri specified in the Intent
            Toast.makeText(this, "Video saved to:\n" +
                     data.getData(), Toast.LENGTH_LONG).show();
        } else if (resultCode == RESULT_CANCELED) {
            // User cancelled the video capture
        } else {
            // Video capture failed, advise user
        }
    }
}
getOutputMediaFile:

private static File getOutputMediaFile(int type){
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.

    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES), "MyCameraApp");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.

    // Create the storage directory if it does not exist
    if (! mediaStorageDir.exists()){
        if (! mediaStorageDir.mkdirs()){
            Log.d("MyCameraApp", "failed to create directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile;
  if(type == MEDIA_TYPE_VIDEO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
        "VID_"+ timeStamp + ".mp4");
    } else {
        return null;
    }

    return mediaFile;
}

如果您想创建自己的文件夹,则必须在此处进行更改

 File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES), "MyCameraApp");
其中,“MyCameraApp”是您的文件夹名称,因此您可以替换为您的文件夹和环境。getExternalStoragePublicDirectory(Environment.DIRECTORY\u PICTURES)这是您的目录,如果您只想保存SD卡,请替换为Environment.getExternalStorageDirectory。在/sdcard/your\u folder\u name/your\u video\u file.mp4中创建一个文件夹