How to check whether a file is present in external storage?
I want to play a video from external storage if that file is present in it otherwise download it from server. I tried
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();
}
The problem with above code is that it is always playing video from server.
I also tried-
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();
}
Problem with this is that it is always playing video from external storage.