如何在不向用户公开原始文件的情况下将视频文件存储在 android 中?

How to store video files in android without exposing raw files to the users?

我正在使用 Google VR SDK 开发一个 VR 应用程序。由于应用程序的性质,用户经常在 day.Using 中播放相同的视频,下面的代码我播放来自 URL 的视频和这个消耗这么多带宽

我想减少带宽 usage.I 认为我可以将视频存储在 phone 内存中,这样下次他们播放时可以简单地从内存中播放,但在这种情况下用户可以轻松访问我的文件和偷它

那么有没有办法做到这一点(比如某种缓存)而不只是让用户看到我的原始视频文件?

 class VideoLoaderTask extends AsyncTask<Pair<Uri, Options>, Void, Boolean> {
    @Override
    protected Boolean doInBackground(Pair<Uri, Options>... fileInformation) {
        try {

                Options options = new Options();
                options.inputFormat= Options.FORMAT_DEFAULT;
                options.inputType = Options.TYPE_MONO;
                Uri myUri = Uri.parse("video.mp4");
                videoWidgetView.loadVideo(myUri, options);

        } catch (IOException e) {
            // An error here is normally due to being unable to locate the file.
            loadVideoStatus = LOAD_VIDEO_STATUS_ERROR;
            // Since this is a background thread, we need to switch to the main thread to show a toast.
            videoWidgetView.post(new Runnable() {
                @Override
                public void run() {
                    Toast
                            .makeText(SimpleVrVideoActivity.this, "Error opening file. ", Toast.LENGTH_LONG)
                            .show();
                }
            });
            Log.e(TAG, "Could not open video: " + e);
        }

        return true;
    }
}

我在developer.android.com中找到了解决方案。我可以简单地将文件保存到存储

String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
//Context.MODE_PRIVATE makes them invisible to users
fos.write(string.getBytes());
fos.close();