mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
Refactor audio conversion and enhance playback experience
Updated `AudioConverter` to streamline null checks and return empty arrays. Added OGG to WAV conversion in `AssetAPI` for better audio handling. Modified `AudioTab` to preload audio automatically, improving user experience. Related: #1877
This commit is contained in:
parent
206f0ec99b
commit
645ed5a336
@ -8,14 +8,11 @@ public static class AudioConverter
|
||||
{
|
||||
public static byte[] OggToWav(byte[] oggData)
|
||||
{
|
||||
if (oggData == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(oggData));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(oggData);
|
||||
|
||||
if (oggData.Length == 0)
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
@ -28,7 +25,7 @@ public static class AudioConverter
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error(LogCategory.Export, "Failed to convert audio from OGG to WAV", ex);
|
||||
return Array.Empty<byte>();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,6 +181,15 @@ internal static class AssetAPI
|
||||
}
|
||||
else if (AudioClipDecoder.TryDecode(clip, out byte[]? decodedAudioData, out string? extension, out _))
|
||||
{
|
||||
if (extension is "ogg")
|
||||
{
|
||||
byte[] wavData = AudioConverter.OggToWav(decodedAudioData);
|
||||
if (wavData.Length > 0)
|
||||
{
|
||||
decodedAudioData = wavData;
|
||||
extension = "wav";
|
||||
}
|
||||
}
|
||||
return Results.Bytes(decodedAudioData, $"audio/{extension}").ExecuteAsync(context);
|
||||
}
|
||||
else
|
||||
|
||||
@ -28,7 +28,7 @@ internal sealed class AudioTab : AssetHtmlTab
|
||||
{
|
||||
using (new Td(writer).WithAlign("center").WithCustomAttribute("valign", "middle").End())
|
||||
{
|
||||
new Audio(writer).WithControls("").WithClass("mt-4").WithSrc(Source).Close();
|
||||
new Audio(writer).WithControls("").WithPreload("auto").WithClass("mt-4").WithSrc(Source).Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user