简体   繁体   中英

How to access file in android internal storage for unity app?

I am using EasyMovieTexture plugin and I want to get access to android folder where all the videos are saved. First I tried to access the streaming asset folder but it is not accessible in the app ( Copying files into asset folder in android ) so I have created folder in which all the videos are and I want to access that particular folder to play the videos individually. Here is a sample code which loads the video from url but I want it to access it from storage -

void OnGUI() {


    if( GUI.Button(new Rect(50,50,100,100),"Load"))
    {
        scrMedia.Load("Url of video");
        m_bFinish = false;
    }

how to access the videos in interval storage to play them. Thanks in advance.

You can use Application.persistentDataPath to access internal storage.

https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

You can see which directory it is using

Debug.log(Application.persistentDataPath)

Any files in a StreamingAssets folder will be included in your build, accessible at the path specified by Application.streamingAssetsPath .

However, the manual mentions an important caveat for Android:

On Android, the files are contained within a compressed .jar file (which is essentially the same format as standard zip-compressed files). This means that if you do not use Unity's WWW class to retrieve the file, you need to use additional software to see inside the .jar archive and obtain the file.

If your video plugin can access the file within an APK, then you'll just need to specify the correct path.

If your video plugin expects a conventional file, then you will need to create one. Unity's WWW class can read the compressed file into memory, which you could then write to some other location (such as Application.temporaryCachePath ) with System.File.WriteAllBytes .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM