Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Is it possible to download video into the StreamingAssets folder ?

Discussion in 'Scripting' started by Kiupe, Feb 1, 2016.

  1. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hi guys,

    I have an app which contains heavy videos and reach out the Google Play app limit size. So far my videos are in the StreamingAssets folder - I'm looking for a solution to remove those video to my build and then download them during the first runtime of the application. It seems that AssetBundle are not a solution - what would you do in my situation ?

    Thanks
     
  2. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    There's WWW.LoadFromCacheOrDownload for doing that with one command. Be wary of cache limits though. Asset bundles are a solution because you can use them with that command. Directly downloading clips that can be streamed with WWW (I know audio can, don't remember about video) should work too.
     
    Last edited: Feb 1, 2016
  3. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hi,

    I'm not quite sure to understand your solution - Asset bundles seem to be used to download and access assets but in my case I want to be able to download and play videos - to do so video files has to be in the StreamingAssets folder - how would you download an AssetBundle containing video and then "move/extract" those videos to the StreamingAssets folder ?

    Thank you
     
  4. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Ok - I never used this function - it returns a WWW and then, what should I do ? From a WWW there is a movie property but it's a MovieTexture which is not usable in Android nor iOS. How to access to the movie file from a WWW instance and then "move/write" this movie file to the StreamingAssets folder ?

    Thank you
     
  5. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    Well, yeah, my miss. It can't be packed and that method only works with asset bundles (as stated in it).
    You should try to download movie manually(through Sockets or from unity server using UNET or any other way to download file), save it into file(as what you've downloaded is byte array) and then open using WWW to load file in path file://path.

    WWW is container for whatever you download. First you check if WWW.error is null; if it isn't - error occured. Then you wait until WWW.isDone (usually done in coroutine) or WWW.error occured; then you access MovieTexture from WWW.movie. If that's something else you've downloaded(like asset bundle) there are properties for them in WWW like .audioClip .assetBundle etc.

    If you manage to force WWW to download whole video you can write WWW.bytes into file and later just load it, but because MovieTexture is streamed it might not be possible.
    This topic on stackoverflow states it actually can be downloaded using WWW even though it's streamed. But I've not tested that.
     
    Last edited: Feb 1, 2016
  6. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
  7. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    Using that method - yes, it might not possible. (You can still try)
    But you can render a fullscreen quad with MovieTexture and Play() it manually instead.
     
    Last edited: Feb 1, 2016
  8. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Actually MovieTextures are not supporter on iOS and Android - that's why I'm trying to figure out a solution to download videos inside the StreamingAssets folder. But maybe it's simply not possible.

    Thanks a lot for your time.
     
  9. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
  10. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Ho ho, I made google searches but obviously not with the right key words. Thanks for the link !
     
    Carterryan1990 likes this.
  11. madhu_unity425

    madhu_unity425

    Joined:
    Oct 25, 2018
    Posts:
    8
    could you please help me how to download images to the streamingaseets folder

    the images should be in streaming assets at run time
     
  12. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,772
    You cannot reliably download files to Streaming Assets at run time. That directory is read-only on many platforms and can be such on even more depending on configuration. I.e. on Windows if you install app system wide and use that app by non-admin user, the install directory (where streaming assets is located) is read-only.
    You should be downloading things to Application.persistentDataPath or Application.temporaryCachePath, those directories are writable.
     
    spark-man likes this.