【问题标题】:Unity www "aborted" errorUnity www“中止”错误
【发布时间】:2016-11-23 14:56:59
【问题描述】:

我有以下错误

当我尝试下载带有统一 www 类的 mp4 文件时,它失败了,在 www.error 中只有“中止”错误消息

这是一个奇怪的错误,它只出现在某些设备上,我已经在 Galaxy Note 5 上尝试过并且效果很好,当有人在 Galaxy s7 上尝试过时,他得到了这个错误

任何人都知道什么是hapening?

感谢你们的帮助。

下载视频的代码

private IEnumerator DownloadVideo()
{
    showDownloadProgress = true;
    downloadProgress.gameObject.SetActive(true);

    videoURL = MainPlayerCTRL.mediaURL;
    Uri uri = new Uri(videoURL);
    string filename = System.IO.Path.GetFileName(uri.LocalPath);
    string localFilePath = Application.persistentDataPath + "/"+ filename;
    bool tryVideoDownload = true;

    if (!File.Exists(localFilePath))
    {
        while (tryVideoDownload)
        {
            downloadProgressText.text = "Downloading";
            showDownloadProgress = true;
            downloadProgress.gameObject.SetActive(true);

            www = new WWW(videoURL);
            yield return www;
            if (String.IsNullOrEmpty(www.error))
            {
                byte[] bytes = www.bytes;
                FileStream fs = new FileStream(localFilePath, FileMode.Create);
                fs.Write(bytes, 0, bytes.Length);
                downloadProgressText.text = "Download done!";
                yield return new WaitForSeconds(2);
                tryVideoDownload = false;
            }//Video downloaded
            else
            {
                showDownloadProgress = false;
                downloadProgress.gameObject.SetActive(true);
                downloadProgressText.text = "Download ERROR \n ";
                downloadProgressText.text += www.error;
                yield return new WaitForSeconds(2);
                downloadProgressText.text = "Attempting to download again";
                yield return new WaitForSeconds(2);
                tryVideoDownload = true;
            }
        }

        yield return new WaitForEndOfFrame();
    }

}

【问题讨论】:

  • 视频有多大?另外,它失败的设备型号是什么?这很可能是内存问题。在不知道所有这些信息的情况下还不确定。
  • 视频大小为 250 mb,您认为可能是临时内存问题?智能手机的内部和外部存储空间超过 2GB。
  • Internal and External storage != Ram。人们混淆了这两者。我曾经遇到过这个问题,并为它写了一个解决方案。如果我在我的电脑上找到它会给出答案。
  • 是的,我知道区别,我的意思是,如果您认为问题可能是(内存)或内部/外部存储问题
  • 哦,好的。没明白。很有可能是公羊。大约一个小时后回来查看这个问题。

标签: c# android unity3d unity5


【解决方案1】:

我怀疑的第一件事是使用FileStream 复制大文件时通常会发生内存不足,但您提到您从www.error 收到“中止”错误。罪魁祸首可能是WWW,首先要做的是使用UnityWebRequest。我用UnityWebRequest 替换了你函数中的WWW

您需要在顶部包含using UnityEngine.Networking; 才能使用它。另一件事是 yield return new WaitForEndOfFrame(); 应该在 while 循环内而不是在它之外,使用 yield return null; 更好。

private IEnumerator DownloadVideo()
{
    showDownloadProgress = true;
    downloadProgress.gameObject.SetActive(true);

    videoURL = MainPlayerCTRL.mediaURL;
    Uri uri = new Uri(videoURL);
    string filename = System.IO.Path.GetFileName(uri.LocalPath);
    string localFilePath = Application.persistentDataPath + "/" + filename;
    bool tryVideoDownload = true;

    if (!File.Exists(localFilePath))
    {
        while (tryVideoDownload)
        {
            downloadProgressText.text = "Downloading";
            showDownloadProgress = true;
            downloadProgress.gameObject.SetActive(true);

            UnityWebRequest www = UnityWebRequest.Get(videoURL);
            yield return www.Send();

            if (String.IsNullOrEmpty(www.error))
            {
                byte[] bytes = www.downloadHandler.data;
                FileStream fs = new FileStream(localFilePath, FileMode.Create);
                fs.Write(bytes, 0, bytes.Length);
                downloadProgressText.text = "Download done!";
                yield return new WaitForSeconds(2);
                tryVideoDownload = false;
            }//Video downloaded
            else
            {
                showDownloadProgress = false;
                downloadProgress.gameObject.SetActive(true);
                downloadProgressText.text = "Download ERROR \n ";
                downloadProgressText.text += www.error;
                yield return new WaitForSeconds(2);
                downloadProgressText.text = "Attempting to download again";
                yield return new WaitForSeconds(2);
                tryVideoDownload = true;
            }

            yield return null;
        }
    }
}

【讨论】:

  • 谢谢,我会在这两种设备上试一试,然后告诉你它是如何工作的。
  • 好的。将等待
  • 嗨,它在 Galaxy Note 5 设备中运行良好,就像我使用 www 时一样,但在 s7 设备中,应用程序启动时应用程序崩溃(下载视频场景)
  • 我觉得问题可能出在设备上?
  • 现在确定设备还为时过早。你能评论除UnityWebRequest之外的所有代码吗?我将使用它来确定下一步该做什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-15
  • 2016-10-12
  • 2016-12-06
  • 2013-10-05
  • 2012-11-26
  • 1970-01-01
相关资源
最近更新 更多