1

I have an Augmented Reality scene which downloads an AssetBundle containing a video. The video is set to Play on Awake so that it plays as soon as it is downloaded and instantiated. On iOS the all works perfectly, however on Android, the AssetBundle downloads and instantiates but only shows the white plane and doesn't play the video. However, if you exit the scene or the App and try again, it works the second time as it's supposed to.

Unity version: 2020.1.11f1 Device: Samsung S8 & Samsung Tab S5 e

This is the script I'm using to download and cache the AssetBundle:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine.Video;

namespace UnityLibrary{
    public class VideoLoader : MonoBehaviour
{
    public string assetBundleURL;

public void Awake(){
       Caching.compressionEnabled = false;
}
  public void Start()
    {
        StartCoroutine(DownloadAndCache(assetBundleURL));
    }
IEnumerator DownloadAndCache(string bundleURL, string assetName = ""){
    while(!Caching.ready){
        yield return null;
    }

    UnityWebRequest www = UnityWebRequest.Get(bundleURL + ".manifest?r=" + (Random.value * 9999999));
    Debug.Log("Loading manifest: " + bundleURL + ".manifest");
    yield return www.SendWebRequest();

    while(!www.isDone)
    Debug.Log("BUNDLE IS DOWNLOADING");

    if(www.isDone)
    Debug.Log("BUNDLE DOWNLOAD COMPLETE");
    if(www.isNetworkError == true){
        Debug.Log("www.error: " + www.error);
        www.Dispose();
        www=null;
        yield break;
    }
    Hash128 hashString = (default(Hash128));
    if(www.downloadHandler.text.Contains("ManifestFileVersion")){
        var hashRow = www.downloadHandler.text.ToString().Split("\n".ToCharArray()) [5];
        hashString = Hash128.Parse(hashRow.Split(':')[1].Trim());

        if(hashString.isValid == true){
            if(Caching.IsVersionCached(bundleURL, hashString) == true){
                Debug.Log("Bundle with this hash is already cached!");
            } else{
                Debug.Log("No cached version found for this hash...");
            }
        } else{
            Debug.Log("Invalid hash: " + hashString);
            yield break;
        }
    } else{
        Debug.LogError("Manifest doesnt contain string 'Manifest version': " + bundleURL + ".manifest");
        yield break;
    }
    www = UnityWebRequestAssetBundle.GetAssetBundle(bundleURL + "?r=" + (Random.value * 9999999), hashString, 0);
    yield return www.SendWebRequest();

    if(www.error !=null){
        Debug.LogError("www.error: " + www.error);
        www.Dispose();
        www = null;
        yield break;
    }
    AssetBundle bundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle;
    GameObject bundlePrefab = null;

    if(assetName == ""){
        bundlePrefab = (GameObject)bundle.LoadAsset(bundle.GetAllAssetNames()[0]);
    }else{
        bundlePrefab = (GameObject)bundle.LoadAsset(assetName);
    }
    if(bundlePrefab !=null){
       var tiles = Instantiate(bundlePrefab, Vector3.zero, Quaternion.identity);
tiles.transform.SetParent(gameObject.transform, false);

Debug.Log("VIDEO GO!");


    }
    www.Dispose();
    www = null;
    Resources.UnloadUnusedAssets();
    bundle.Unload(false);
    bundle = null;
}
}
}
HollyC
  • 81
  • 5

0 Answers0