Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can't load audioclip on runtime

Discussion in 'Android' started by Hermonirr, Oct 1, 2019.

  1. Hermonirr

    Hermonirr

    Joined:
    Dec 23, 2013
    Posts:
    56
    Hi,

    I'm trying to load mp3s from the device and play them back.

    This code works fine in the editor, but on the device I get the network error:
    Cannot connect to destination host

    Code (CSharp):
    1.     IEnumerator Load_Song(string uri)
    2.     {
    3.         Utils.DebugLogAdd("Inside Load_Song, loading: " + uri);
    4.  
    5.         Song newSong = new Song();
    6.         newSong.uri = uri;
    7.  
    8.         Utils.DebugLogAdd("Created new song");
    9.         using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.MPEG))
    10.         {
    11.             Utils.DebugLogAdd("Waiting for UnityWebRequest");
    12.             yield return www.SendWebRequest();
    13.  
    14.             if (www.isNetworkError)
    15.             {
    16.                 Utils.DebugLogAdd("*** Network error: " + www.error);
    17.             }
    18.             else
    19.             {
    20.                 loadedClip = DownloadHandlerAudioClip.GetContent(www);
    21.                 loadedClip.name = Path.GetFileNameWithoutExtension(uri);
    22.                 newSong.clip = loadedClip;
    23.                 if(Song_Added_Action != null)
    24.                     Song_Added_Action(newSong, loadedClip);
    25.             }
    26.         }
    27.        }
    28.  
    Thanks in advance