Reputation: 153
I have actually created a script in which I first locate the video file by path and used the same path for the System.IO.File.Exists(filePath) The conditions which I set are P1.GetComponent ().enabled = false; if file exists and P1.GetComponent ().enabled = true; if the file does not exist and given reference P1(also others).and called the function in update function for continuous check. It works as it is not able to find the file (the location of the file or path is correct I have check many times) and returns true but the other condition does not work. I have also tried debugging on running app and I got this
6580 6607 I Unity : file:///storage/emulated/0/Android/data/com.app.app/cache/folder23/video.mp4
6580 6607 I Unity :
6580 6607 I Unity : (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
previously I also created a delete button(in editor and android both) and it works with the same path but do not know what is causing this to not work when exported in android.
Here is the code -
string filePath = "file://" + Application.temporaryCachePath + "/" + "folder23" + "/" + fileName + fileExtension;
if (System.IO.File.Exists(filePath)) {
Panel.GetComponent<Canvas> ().enabled = false;
}
else if(!System.IO.File.Exists(filePath)) {
Panel.GetComponent<Canvas> ().enabled = true;
}
Upvotes: 2
Views: 2113
Reputation: 308
If I understood, you have some file under Application.temporaryCachePath in Editor and you suppose it would be under this path on device? That's wrong assumption. If you want to use any 'external' files (not project assets) you have two options.
Create "Resources" folder in your Assets folder and place the video there. You will unfortunately have to change the extension to ".bytes" or any other from Here that Unity can read that as Resources asset. Then you can load it using
TextAsset bin = Resources.Load("video") as TextAsset;
Keep in mind that you won't find this folder on device under Application.dataPath + "Resources" or any other path. It is being processed by unity and packed into build and the only way to load files from there is to use Resources class.
Other way is to create StreamingAssets folder in your Assets folder. This is a special folder that goes into the build 'raw'. So, everything you put there will go unmodified into build under Application.streamingAssetsPath. However, on Android it's little bit more complicated since streamingAssetsPath points to .apk file and you need to extract the file from the apk first. Here is described how to do that. I would rather recommend you using Resources.
Upvotes: 1