我正在使用Google VR SDK开发VR应用程序。由于应用程序用户的性质,他们经常在一天内播放相同的视频。使用下面的代码我从URL播放视频,这会占用大量带宽
我想减少带宽使用量。我想我可以将视频存储在手机内存中,以便下次播放时可以简单地从内存播放,但在这种情况下,用户可以轻松访问我的文件并窃取它
有没有办法做到这一点(比如某种缓存),但没有简单地将用户暴露给我的原始视频文件?
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;
}
}
答案 0 :(得分:0)
我在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();