Skip to content

Commit

Permalink
com.utilities.rest 2.5.1 (#67)
Browse files Browse the repository at this point in the history
- added compressed and streamingAudio flags to Rest.DownloadAudioClipAsync
  • Loading branch information
StephenHodgson committed Jan 28, 2024
1 parent cea876e commit 391139f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Runtime/Rest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ public static bool TryGetFileNameFromUrl(string url, out string fileName)
/// <param name="httpMethod">Optional, must be either GET or POST.</param>
/// <param name="jsonData">Optional, json payload. Only <see cref="jsonData"/> OR <see cref="payload"/> can be supplied.</param>
/// <param name="payload">Optional, raw byte payload. Only <see cref="payload"/> OR <see cref="jsonData"/> can be supplied.</param>
/// <param name="compressed">Optional, Create AudioClip that is compressed in memory.<br/>
/// Note: When <see cref="streamingAudio"/> is true, it supersedes compression, and the download handler creates an AudioClip similar
/// to an imported clip with the loadType AudioClipLoadType.Streaming.
/// </param>
/// <param name="streamingAudio">Optional, Create a streaming audio clip.</param>
/// <param name="parameters">Optional, <see cref="RestParameters"/>.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns>A new <see cref="AudioClip"/> instance.</returns>
Expand All @@ -593,6 +598,8 @@ public static bool TryGetFileNameFromUrl(string url, out string fileName)
string fileName = null,
string jsonData = null,
byte[] payload = null,
bool compressed = false,
bool streamingAudio = false,
RestParameters parameters = null,
CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -624,6 +631,8 @@ public static bool TryGetFileNameFromUrl(string url, out string fileName)

UploadHandler uploadHandler = null;
using var downloadHandler = new DownloadHandlerAudioClip(url, audioType);
downloadHandler.compressed = compressed;
downloadHandler.streamAudio = streamingAudio;

if (httpMethod == UnityWebRequest.kHttpVerbPOST)
{
Expand All @@ -634,7 +643,7 @@ public static bool TryGetFileNameFromUrl(string url, out string fileName)
throw new ArgumentException($"{nameof(payload)} and {nameof(jsonData)} cannot be supplied in the same request. Choose either one or the other.", nameof(jsonData));
}

payload = new UTF8Encoding().GetBytes(jsonData);
payload = new UTF8Encoding().GetBytes(jsonData!);

var jsonHeaders = new Dictionary<string, string>
{
Expand Down Expand Up @@ -737,7 +746,7 @@ public static bool TryGetFileNameFromUrl(string url, out string fileName)
throw new ArgumentException($"{nameof(payload)} and {nameof(jsonData)} cannot be supplied in the same request. Choose either one or the other.", nameof(jsonData));
}

payload = new UTF8Encoding().GetBytes(jsonData);
payload = new UTF8Encoding().GetBytes(jsonData!);

var jsonHeaders = new Dictionary<string, string>
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Utilities.Rest",
"description": "This package contains useful RESTful utilities for the Unity Game Engine.",
"keywords": [],
"version": "2.5.0",
"version": "2.5.1",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest/releases",
Expand Down

0 comments on commit 391139f

Please sign in to comment.