Cysharp / YetAnotherHttpHandler

YetAnotherHttpHandler brings the power of HTTP/2 (and gRPC) to Unity and .NET Standard.
MIT License
362 stars 32 forks source link

Unity - Loading Assets/Audio Clips etc. #44

Open LiamKarlMitchell opened 9 months ago

LiamKarlMitchell commented 9 months ago

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

robotwai commented 6 months ago

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);
        }`