I just heard that the licenses on MP3 have expired or will expire soon ( Patents On MP3 Format Due To Expire | Hackaday )
Is this true? If yes, are there plans by Unity to support MP3 on the same level as OGG?
I am interested in loading MP3 at runtime and streaming MP3 files via UnityWebRequestMultimedia.GetAudioClip
MP3 is still a widely used format by users. Thus, I think full support for this audio file format in C# and web requests would be highly appreciated. Note that the web request also works for local files when using file:// protocol
Turns out this is working already?!
When did this change? I tried it like three years ago and MP3 was not working using UnityWebRequestMultimedia.
Anyway, thanks Unity for adding streaming of MP3 files at runtime! Works like a charm, awesome!
Example:
// uri is "file://F:\Dev\test.mp3"
private static AudioClip LoadAudio(string uri, bool streamAudio)
{
Debug.Log($"Loading audio from {uri}");
using (UnityWebRequest webRequest = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.UNKNOWN))
{
DownloadHandlerAudioClip downloadHandler = webRequest.downloadHandler as DownloadHandlerAudioClip;
downloadHandler.streamAudio = streamAudio;
webRequest.SendWebRequest();
if (webRequest.result
is UnityWebRequest.Result.ConnectionError
or UnityWebRequest.Result.ProtocolError)
{
Debug.LogError("Error Loading Audio: " + uri);
Debug.LogError(webRequest.error);
return null;
}
while (!webRequest.isDone)
{
Task.Delay(30);
}
return downloadHandler.audioClip;
}
}
Tested with Unity 2021.2.0f1 on Windows 11.