将捕获的视频存储在特定文件夹中并在视频视图中播放视频

Store captured video in specific folder and play the video in a video view

我需要一个简单的代码来存储视频并在 videoview 中显示 我需要一个简单的代码来存储视频并在 videoview 中显示。

 Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
                startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);

我是新开发者。我创建应用程序。我需要将视频存储在特定文件夹中,还需要在视频视图中查看视频。

此代码有效

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

        if (resultCode == RESULT_OK)
        {
            try
            {
                AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(data.getData(), "r");
                FileInputStream fis = videoAsset.createInputStream();
                File root=new File(Environment.getExternalStorageDirectory(),"/RecordVideo/");  //you can replace RecordVideo by the specific folder where you want to save the video
                if (!root.exists()) {
                    System.out.println("No directory");
                    root.mkdirs();
                }

                File file;
                file=new File(root,"android_"+System.currentTimeMillis()+".mp4" );

                FileOutputStream fos = new FileOutputStream(file);

                byte[] buf = new byte[1024];
                int len;
                while ((len = fis.read(buf)) > 0) {
                    fos.write(buf, 0, len);
                }
                fis.close();
                fos.close();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    }