<分区>
如何检查外部存储中是否存在文件?
我想播放来自外部存储的视频,如果该文件存在于其中,否则从服务器下载。 我试过了
if ((Environment.getExternalStorageDirectory().getPath().contains(mVideo.getCaption() + ".mp4"))) {
videoPath = Environment.getExternalStorageDirectory().getPath() + "/" + mVideo.getCaption() + ".mp4";
Toast.makeText(getActivity(), "Playing from External storage" + videoPath, Toast.LENGTH_LONG).show();
} else {
videoPath = URLs.VIDEO_URL.replace("<fixme>", mVideo.getId());
Toast.makeText(getActivity(), "Playing from Server" + videoPath, Toast.LENGTH_LONG).show();
}
上面代码的问题是它总是从服务器播放视频。
我也试过-
if ((Environment.getExternalStorageDirectory().getPath() + "/" + mVideo.getCaption() + ".mp4")!=null) {
videoPath = Environment.getExternalStorageDirectory().getPath() + "/" + mVideo.getCaption() + ".mp4";
Toast.makeText(getActivity(), "Playing from External storage" + videoPath, Toast.LENGTH_LONG).show();
} else {
videoPath = URLs.VIDEO_URL.replace("<fixme>", mVideo.getId());
Toast.makeText(getActivity(), "Playing from Server" + videoPath, Toast.LENGTH_LONG).show();
}
问题是它总是从外部存储播放视频。