Quantcast
Channel: Questions in topic: "webrequest"
Viewing all articles
Browse latest Browse all 387

How to stream audio before completely downloaded?

$
0
0
Hi, I am trying to stream mp3 audio from an url. It works well, but I have to wait until audio is downloaded fully before the stream starts. I know that audio could start before the whole download is completed, just don't know how. Here is my code: void Start () { audioSource = GetComponent(); } // Update is called once per frame void Update () { //TESTING if(Input.GetKeyUp(KeyCode.P)){ StartCoroutine(GetAudio("https://firebasestorage.googleapis.com/v0/b/showstopper-3cd1b.appspot.com/o/Shlijani%20-%20Crna%20Ovca.mp3?alt=media&token=ab5a6ece-da3e-45d2-832a-3c202be7f5be")); } } public IEnumerator GetAudio(string url){ Debug.Log("Get audio"); UnityWebRequest musicRequest = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.MPEG); yield return musicRequest.SendWebRequest(); if (musicRequest.isNetworkError) { Debug.Log(musicRequest.error); Debug.Log(musicRequest.responseCode); } else { handler = (DownloadHandlerAudioClip)musicRequest.downloadHandler; handler.streamAudio = true; AudioClip clip = handler.audioClip; Debug.Log(clip + " length: " + clip.length); if (clip) { audioSource.clip = clip; Debug.Log("Audio clip not null"); audioSource.Play(); } } }

Viewing all articles
Browse latest Browse all 387

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>