Use Easy Save to download a mp4 file from WWW

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
PET
Posts: 26
Joined: Mon Feb 22, 2016 1:23 pm

Use Easy Save to download a mp4 file from WWW

Post by PET »

Hello there!

I'm kind of in a weird spot. I'm making a small app (PC & Android) using PlayMaker.

I recently found out that if I use the WWW Unity class that file get's stored into Memory and I don't want that.
Could I use Easy Save to do this:

1. Check if the file has already been downloaded. If NOT:
2. Download the MP4 file (it will be around 1 GB)
3. Get the full path location of that file (PC & Android, I will make 2 sepparate versions)
4. Store that full location in a PlayMaker variable so I can pass it to another script.

Can I do this with EasySave ?


Thanks bro! <3

User avatar
Joel
Moodkie Staff
Posts: 3385
Joined: Wed Nov 07, 2012 10:32 pm

Re: Use Easy Save to download a mp4 file from WWW

Post by Joel »

Hi there,

That is indeed possible.

Firstly, you would use the Exists action to check whether the file has been previously downloaded or not.

If the file hasn't been downloaded, use the Download File action to download the file from a URL to local storage. Because you're downloading a file rather than from a database, you only need to set the Local Filename and Url fields ... all other fields can be left as their default values.

Then to get the default save location, you can use the Get Persistent Data Path action to get the location of the save folder, and set the Append String to the local filename with a slash appended to the beginning (i.e. /myFilename.mp4).

All the best,
Joel
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

PET
Posts: 26
Joined: Mon Feb 22, 2016 1:23 pm

Re: Use Easy Save to download a mp4 file from WWW

Post by PET »

C:/Users/bogda/AppData/LocalLow/GamerPET/Extrav/test.pdf

This is beautiful man! :D
Hopefully I woun't require to get the file size... and create some kind of "download bar".

PET
Posts: 26
Joined: Mon Feb 22, 2016 1:23 pm

Re: Use Easy Save to download a mp4 file from WWW

Post by PET »

Everything works great so far. I'm even using the Delete Action :D

Would it be possible to add some kind of... progress... bar or to check the size of the file and display it?

Thanks bro!

<3

User avatar
Joel
Moodkie Staff
Posts: 3385
Joined: Wed Nov 07, 2012 10:32 pm

Re: Use Easy Save to download a mp4 file from WWW

Post by Joel »

Glad to hear it!

I've attached below an update for the Playmaker actions which has a Progress property which will be update with the progress of the download, assuming your server sends the required headers for it to work. It'll be a value between 0.0 and 1.0, where 1.0 means the download is complete.

All the best,
Joel
Attachments
ES2Playmaker.unitypackage
(8.52 KiB) Downloaded 279 times
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

PET
Posts: 26
Joined: Mon Feb 22, 2016 1:23 pm

Re: Use Easy Save to download a mp4 file from WWW

Post by PET »

Joel wrote:Glad to hear it!

I've attached below an update for the Playmaker actions which has a Progress property which will be update with the progress of the download, assuming your server sends the required headers for it to work. It'll be a value between 0.0 and 1.0, where 1.0 means the download is complete.

All the best,
Joel
Thanks!

Image

PET
Posts: 26
Joined: Mon Feb 22, 2016 1:23 pm

Re: Use Easy Save to download a mp4 file from WWW

Post by PET »

I'm doing some more tests.

From what I see the plugin first downloads the file into memory, then it writes the file on disk... which is why when you hit 100% it hangs for some time.
Since I'm trying to download a file (mp4) to a mobile device... it hangs for a long long time.

Is there any way to ... make the download better? Besides making the video itself much smaller so the phone can handle it.

Another version that I might try is to split the video into multiple parts and download all the parts... but dunno yet.

User avatar
Joel
Moodkie Staff
Posts: 3385
Joined: Wed Nov 07, 2012 10:32 pm

Re: Use Easy Save to download a mp4 file from WWW

Post by Joel »

Hi there,

It's not possible to download and save the data incrementally to file as it's downloaded as we're required to use Unity's WWW class, which does not provide access to the bytes until after it's finished downloading.

In code, you might be able to access the data field of the ES2Web object to get the downloaded bytes, and then iterate through this byte array using ES2.AppendRaw to incrementally add bytes to the file. Something like:
public IEnumerator Download(string url, string localFile, long bytesPerIteration)
{
    var web = new ES2Web(url);
    yield return StartCoroutine(web.Download());
    if(web.isError)
        Debug.LogError(web.error);
    else
    {
        var bytes = web.data;
        long offset = 0;

        while(offset < bytes.Length)
        {
            int length = System.Math.Min(bytesPerIteration, bytes.Length - offset);
            var buffer = new byte[length];
            Buffer.BlockCopy(bytes, offset, buffer, 0, length);
            ES2.AppendRaw(buffer, localFile);
            offset += length;
            // Wait until the next frame before writing more data.
            yield return null;
        }
    }
}
However this will only help if the performance spike is caused by the quantity of data rather than the overhead of creating, opening and writing to the file. The entirety of the downloaded data will still be stored in memory.

All the best,
Joel
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

PET
Posts: 26
Joined: Mon Feb 22, 2016 1:23 pm

Re: Use Easy Save to download a mp4 file from WWW

Post by PET »

Hello Joel,

could you help me by answering some questions?

I'm trying to improve my app by making it more inclusive. Basically have the same scene do multiple thinkgs like:

- Get a list with all my Game Objects that are videos. Basically just some Game Objects that have a Playmaker FSM that has an Array List that contains the download links.
- Look trough that list doing:
-- Check to see if the Array List only has 1 element. Meaning that the file only has 1 part.
-- Check to see if the Array List has multiple elements. Meaning that the video will have multiple parts.
^^ I kind of already made the stuff from above
-- Get the FILENAME of the url. The URL points to http://blabla/bla/MyVideo1.mp4. I only want to get the MyVideo1.mp4. Does EasySave have a way to explode a string and only get the file name?
-- Check to see if the FILENAME has already been downloaded. I know that you have the EXISTS acction. It requires a "filename".
-- Check to see if the FILENAME has manually been placed to : /storage/emulated/0/Movies/BLABLA/[MyFileNameThatIJustTook]

Things get a bit more complicated than this so let's leave it at this for now.

More exact QUESITON:
I know that you have the EXISTS action. It requires a "filename". If I just feed him the variable that has the filename, where is the action going to check for the file? In the App folder? I just need to check if the file has already been downloaded, so I need to check for the download location which I think it's in the "Persistent Data Path"? I think at one point you told me to use the Get Persistent Data Path in order to combine 2 strings and feed a "/" character to the video player :D

Thanks and sorry for this whole big big text.
I could combine 2 strings (a folder location & the filename) to check if the folder is on my /storage/emulated... .

User avatar
Joel
Moodkie Staff
Posts: 3385
Joined: Wed Nov 07, 2012 10:32 pm

Re: Use Easy Save to download a mp4 file from WWW

Post by Joel »

Hi there,

The Exists action will look in the default save location, which unless you've changed the default settings will be Application.persistentDataPath. So if you need to check for the existence of a file in Application.persistentDataPath, you can just provide it with a filename. Also note that the field also accepts absolute paths if you need to check a different directory.

With regards to exploding a string, you will need to check with the Playmaker team whether they have a String.Split action as this more regards string manipulation in general rather than saving and loading data.

All the best,
Joel
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

Locked