Search Unity

Video Load VideoClip in assetbundle on Android

Discussion in 'Audio & Video' started by VianneyThurotte, Apr 18, 2017.

  1. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    188
    The above method had been detailed a couple of times before and works. You can download the bundles to persistent data then load from there. You'd have to write your own caching layer
     
  2. hertatra

    hertatra

    Joined:
    Jul 12, 2017
    Posts:
    1
    You said "Second, use AssetBundle.LoadFromFile() to load your AssetBundle instead of using WWW." but what if my asset bundle is in the server. How can i download from server using AssetBundle.LoadFromFile()?
     
  3. Viewzoom

    Viewzoom

    Joined:
    Jan 16, 2016
    Posts:
    5
    You should download and save the AssetBundle to the persistentDataPath before you Load it.
     
  4. ManuelLoaiza

    ManuelLoaiza

    Joined:
    Jan 3, 2019
    Posts:
    1
    Hi Everyone, in my case I put my complete scene into an assetbundle , in this scene I define a videoclip which is set using a .webm file. This videoclip is played using a videoplayer gameobject. But , how you known in Android I can't play this file from my assetbundle after download and cached it. I test the suggested solution , that is to download this video file from the webserver and copy them to my persistentDataPath and after copy instantiate my videoplayer from this path and read from that my .webm file. This soloution worked ok !!. My question is, inside my assetbundle is zipped my webm file, how I can save or extract the video file inside assetbundle and save it into the persistentDataPath, I load the scene and inside the scene I have a videoclip object that have the referenced to webm file, but how I copy this video file and save it inside my persistentDataPath, anyone have try to do that ???, thanks for your help.
     
  5. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    188

    You can not extract the video from an assetbundle to persistent data. You can either download the assetbundle itself to a file instead of cache and load it from there (uncompressed!), or download the video file separately from the bundle and store it in persistent data.
     
  6. multimediamarkers

    multimediamarkers

    Joined:
    Feb 17, 2016
    Posts:
    24
    Any news from @Unity for solving the bug on video's in Assetbundles for Android?
     
  7. Zapan15

    Zapan15

    Joined:
    Apr 11, 2011
    Posts:
    45
    Please try to use "UnCompressed" AssetBundles on android for videos.
     
  8. lloydhooson

    lloydhooson

    Joined:
    Apr 7, 2008
    Posts:
    64
    Hi, is this issue going to be resolved from asset-bundles that are cached? I'm currently using the "UnityWebRequestAssetBundle.GetAssetBundle" and this for video content fine for iOS, Windows, OSX, but not at all for android. Do I have to change the whole asset-bundle system for video to work on android?

    Thanks.
     
  9. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    188
    Unity doesn't consider this a bug and therefor it won't be "fixed", word from Unity team:

    this is a known limitation. It should have been documented in the first place: I'm adding a line about this in the VideoPlayer API doc so future users don't have to discover this by experimentation. The limitation is imposed by the subset of the Android media API that we are restricting ourselves to, which lets us uniformly support Android versions 16 and up for movie playback.

    Asset bundles are normally accessed by Unity's internals via a filesystem abstraction layer that is specific to Unity, which we call the VFS (Virtual File System). This abstraction lets Unity internal code read "files" in this VFS by abstracting out whether the file content is compressed/uncompressed, in memory or on disk. However, prior to API level 23/6.0 in Java (and 28/9.0 - in C++), the Android media API doesn't allow intercepting i/o calls to redirect them to an arbitrary implementation; in Unity's case, this would be the VFS.
     
    rytalfo likes this.
  10. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    370
  11. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    370
    Is there any progress about this issue?
     
  12. AlekseiBegali

    AlekseiBegali

    Joined:
    Oct 10, 2017
    Posts:
    1
    Hi, had same issue.
    Main problem is between Android native video player and Unity. Android just can't play video file from COMPRESSED Asset Bundles.
    But, when you loading Asset Bundles, despite compressed they are or not, they will be stored in Cache - which can be Compressed or Uncompressed too (UnityEngine.Caching.compressionEnabled). So, if you are downloading compressed Asset Bundle when cache compression is disabled, Android video player WILL play video from that Bundle, because Asset Bundle will be stored uncompressed.
    It's not a solution, but for me I wrote Asset Bundle downloading manager, which enables or disables Cache compression depending on Asset Bundle (if it contains video or not). It's better than leaving all Asset Bundles uncompressed. It saves traffic and device storage.
    Tested on Unity 2018.3.5f1
     
    gamevagrant and nilsdr like this.
  13. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    188
    Can this setting be toggled per assetbundle?
     
  14. UweR7

    UweR7

    Joined:
    Jul 27, 2017
    Posts:
    20
    Thanks for your tip/advise! Sounds good. But in the meantime I wrote my own workaround:
    Aloso videos are separated during asset bundles build.
    Both kinds (videos and asset bundles) are than copied to a server.

    At run time are the asset bundles and the related videos (and other separated files) downloaded, stored on the device and used.
    I wrote also my own caching class to handle it as I like.
     
  15. Shane-Pangea

    Shane-Pangea

    Joined:
    Dec 12, 2012
    Posts:
    21
    @UweR7 that sounds great! Can you share your solution with the thread?
     
  16. Shane-Pangea

    Shane-Pangea

    Joined:
    Dec 12, 2012
    Posts:
    21
    I found this video that explains loading videos from Asset Bundles on Android. Looks like the key is setting the cache compression to false as @AlekseiBegali mentioned. I haven't checked it out for myself yet, but it looks promising!

     
  17. gamevagrant

    gamevagrant

    Joined:
    Aug 7, 2019
    Posts:
    1
    Code (CSharp):
    1.  
    2. private void Awake()
    3.     {
    4.         Caching.ClearCache();
    5.         Caching.compressionEnabled = false;
    6.     }
    7. private IEnumerator LoadAssetBundle(string path, string name)
    8. {
    9.         string assetbundleName = PathUtils.GetAssetBundleNameWithPath(path, FilePathTools.root);
    10.         AssetBundle manifestBundle = AssetBundle.LoadFromFile(FilePathTools.manifestPath);
    11.         AssetBundleManifest manifest = manifestBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
    12.         Hash128 hash = manifest.GetAssetBundleHash(assetbundleName);
    13.  
    14.         string cachePath = FilePathTools.tmpPath;
    15.  
    16.         if (!Directory.Exists(cachePath))
    17.             Directory.CreateDirectory(cachePath);
    18.         Cache newCache = Caching.AddCache(cachePath);
    19.  
    20.         if (newCache.valid)
    21.             Caching.currentCacheForWriting = newCache;
    22.         path = "file://" + path;
    23.  
    24.         UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(path, hash);
    25.         yield return request.SendWebRequest();
    26.         if (!string.IsNullOrEmpty(request.error))
    27.         {
    28.             Debug.LogError(request.error);
    29.             yield break;
    30.         }
    31.         AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);
    32.         var clip = bundle.LoadAsset<VideoClip>(name);
    33.         PlayVideoClip(clip);
    34.         yield return null;
    35.         bundle.Unload(false);
    36.     }
    @AlekseiBegali is right