Search Unity

Bug Unity Streaming audio from url

Discussion in 'Audio & Video' started by Klamore74, Feb 22, 2021.

  1. Klamore74

    Klamore74

    Joined:
    Jun 17, 2013
    Posts:
    103
    I'm trying to stream audio from a web server using the following code in Unity for mobile devices.

    When I start it, I get only a portion of the file that plays in a loop from the beginning.

    Can I fix it? Are there some other robust solutions?

    Code (CSharp):
    1. public IEnumerator TestStreamPlay()
    2. {
    3.     var Source = GetComponent<AudioSource>();
    4.     string pt = "http://www.theeyefeel.com/tmp/ok_boomer_6_versione_2.mp3";
    5.  
    6.     using (var webRequest = UnityWebRequestMultimedia.GetAudioClip(pt, AudioType.UNKNOWN))
    7.     {
    8.         var clipDownloader = (DownloadHandlerAudioClip)webRequest.downloadHandler;
    9.         clipDownloader.streamAudio = true;
    10.  
    11.         webRequest.SendWebRequest();
    12.         while (!webRequest.isNetworkError && webRequest.downloadedBytes < 2048) yield return null;
    13.  
    14.         if (webRequest.isNetworkError)
    15.         {
    16.             Debug.LogError(webRequest.error);
    17.             yield break;
    18.         }
    19.  
    20.  
    21.         var clip = clipDownloader.audioClip;
    22.         Source.PlayOneShot(clip);
    23.     }
    24. }
     
  2. Grimraider1

    Grimraider1

    Joined:
    Jan 12, 2022
    Posts:
    3
    Hi,
    Does anyone can resolve this bug?