- Home /
Question by
BrutalWiz · Apr 01, 2020 at 02:51 PM ·
audioprogrammingdownloadstreamingwebrequest
How to check if DownloadHelperAudioClip still has internet connection for streaming during playback?
Hi, i use a DownloadhelperAudioClip and UnityWebRequests in order to access audio files on a web server from mobile. Now, thinking about stability with WiFi or even Mobile Networt (i create an Android App) i wonder how to check during playback, if the stream is still available? Does anyone know an answer? Thank you. Here is the Method for my Audio Streaming:
public static IEnumerator GetAudioClipAsWebStream(string mp3Url, AudioSource audioSource,AudioType audioType)
{
var downloadHandler = new DownloadHandlerAudioClip(mp3Url,audioType);
downloadHandler.compressed = false;
downloadHandler.streamAudio = true;
UnityWebRequest www = new UnityWebRequest(mp3Url,UnityWebRequest.kHttpVerbGET,downloadHandler,null);
www.SendWebRequest();
while (www.downloadProgress<0.01)
{
yield return new WaitForSeconds(0.1f);
}
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
var clip = downloadHandler.audioClip;
if (clip)
{
audioSource.clip = clip;
audioSource.Play();
}
}
}
Comment