2016-11-23 57 views
1

我有以下錯誤團結WWW「中止」的錯誤

當我嘗試下載與團結WWW類MP4文件它www.error只有「中止」錯誤消息未能

其怪異錯誤,它只出現在一些設備上,我已經在銀河注5上試過了,效果很好,當有人在銀河系s7上試過它時,他得到那個錯誤

任何一個mybe知道什麼是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(); 
    } 

} 
+0

視頻有多大?另外,它失敗的設備型號是什麼?這很可能是一個記憶問題。不知道所有這些信息。 – Programmer

+0

視頻大小是250 MB,你認爲它可能是暫時的內存問題?智能手機的內部和外部存儲容量超過2GB。 –

+0

'內部和外部存儲'!='Ram'。人們混淆了這兩個。我曾經遇到過這個問題,併爲它寫了一個解決方案。如果我在電腦上找到答案,我會回答。 – Programmer

回答

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; 
     } 
    } 
} 
+0

謝謝,我會嘗試在這兩個設備,並會讓你知道它是如何工作的。 –

+0

好的。將等待 – Programmer

+0

嗨,它在炒作星系note5設備,就像當我使用www,但在s7設備應用程序啓動時崩潰(下載視頻場景) –