视频无法在Android上首次播放

问题描述

我有一个增强现实场景,该场景下载了包含视频的AssetBundle。视频设置为“唤醒时播放”,以便在下载并实例化后立即播放。在iOS上,所有功能都可以完美运行,但是在Android上,AssetBundle可以下载并实例化,但仅显示白色平面,不播放视频。 但是,如果退出场景或App并重试,它将按预期第二次运行。

统一版本:2020.1.11f1 设备:三星S8和三星Tab S5 e

这是我用来下载和缓存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;
}
}
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...