Cysharp/YetAnotherHttpHandler

Unity - Loading Assets/Audio Clips etc.

LiamKarlMitchell opened this issue · 1 comments

Hi, I've been able to get the library working in a project and can talk with GRPC and download strings and png just fine.

But curious if it can also be used to load Audio Clips or other formats not necessarily asset bundles or addressables.

The readme says:
It can also be used for asset downloading via HTTP/2, providing more functionality to your projects.

Are there examples of doing this, with UnityWebRequest or UnityWebRequestMultimedia etc we can load AudioClip from a URL with an Ogg, Wav, Mp3.

I'm not seeing a way to easily load AudioClip from other formats, whilst using System.Net.Http.HttpClient with this handler and just wondered if there was something I'm missing.

I could cobble something together but wondering if someone knows how to use the built-in internal ways with Unity rather than use third-party decoder/libs such as https://github.com/gindemit/unity-wrapper-vorbis or https://github.com/NVorbis/NVorbis

Loading audioclip in wav format is normal, decoding to wav is normal via byteString,code like this:
` string directory = new FileInfo(savePath).Directory.FullName;
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);

        File.WriteAllBytes(savePath, audioBytes.ToArray());
        var webRequest = UnityWebRequestMultimedia.GetAudioClip($"file://{savePath}", audioType);


        await webRequest.SendWebRequest().ToUniTask(cancellationToken: cancellationToken);

        if (webRequest.result == UnityWebRequest.Result.ConnectionError)
        {
            Debug.LogWarning(webRequest.error);
            return null;
        }
        else
        {
            return DownloadHandlerAudioClip.GetContent(webRequest);
        }`