Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity - Loading Assets/Audio Clips etc. #44

Open
LiamKarlMitchell opened this issue Feb 3, 2024 · 1 comment
Open

Unity - Loading Assets/Audio Clips etc. #44

LiamKarlMitchell opened this issue Feb 3, 2024 · 1 comment

Comments

@LiamKarlMitchell
Copy link

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
Copy link

robotwai commented Apr 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants