Question by
GospelOfMyHeart · May 23, 2019 at 01:13 PM ·
audioaudioclipstreaming
Streaming audio with UnityWebRequest
I need to stream audio while it`s loading, because audio files are big. I tried DownloadHandlerAudioClip streamAudio set to true and when 0.1 of audio downloaded i`m trying to receive audio from handler. But it generates "Error: Cannot create FMOD::Sound instance for resource 0x*: , (Unsupported file or audio format. )" Code is next:
public override IEnumerator GetData(AudioSource as)
{
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(URL, audioType))
{
// Prepare stream
DownloadHandlerAudioClip downloadHandler = new DownloadHandlerAudioClip("", audioType);
downloadHandler.streamAudio = true;
www.downloadHandler = downloadHandler;
www.SendWebRequest();
AudioClip audioClip = null;
while (www.downloadProgress < 0.1)
{
Debug.Log(www.downloadProgress);
yield return new WaitForSeconds(0.1f);
}
if (www.isNetworkError)
{
Debug.Log("error");
}
else
{
//here goes error
as.clip= downloadHandler.audioClip;
}
yield return 0;
}
}
Comment
Your answer
Follow this Question
Related Questions
How to download and stream AudioClip at the same time 1 Answer
On iOS Build, Audio Gets Muted When App Loses Focus 0 Answers
How to make audio play at once. 1 Answer
Cracking at end of audio? 0 Answers