Hi there!
So basically, I got some mp3 as streaming assets in the “StreamingAssets” folder of the application. The files are always local. I can retrieve them and play them on WebGL and Android builds with UnityWebRequestMultimedia using that code:
DownloadHandlerAudioClip dHA = new DownloadHandlerAudioClip(path, AudioType.MPEG);
dHA.streamAudio = false; // You can set this to true if you want to stream
www.downloadHandler = dHA;
www.timeout = 10;
// Send the request and wait for it to complete
yield return www.SendWebRequest();
if (www.responseCode != 200 || www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogError($"Error loading audio clip: {www.error}, Response Code: {www.responseCode}");
}
else
{
Debug.LogWarning($"Succed loading audio clip: {www.error}, Response Code: {www.responseCode}");
AudioClip currentAudioClip = DownloadHandlerAudioClip.GetContent(www);
}
on iOS I can validate that the files are accessible:
audioClipPath = Application.dataPath + "/Raw/Voices/" + LocalizationManager.CurrentLanguageCode + "/" + key + ".mp3";
if (System.IO.File.Exists(audioClipPath))
{
Debug.Log("File exists");
}
I can’t use the UnityWebRequest as it returns 0 with the correct path. I did try a lot of various paths just in case but never seems to have found something that works.
In the documentation it doesn’t say what I could use to play the mp3 files in this case Unity - Manual: Streaming Assets (unity3d.com) as the UnityWebRequest solution is required only for WebGL and Android.
That leaves me with only one solution, reading the file as Byte and using another dll library to decode the mp3 file to play it inside Unity. I found another post here:
Anyone been able to load an audio file from local filesystem on iOS and playback a clip? - Questions & Answers - Unity Discussions
I just wonder if I have tested this correctly and if there is not a simpler solution using UnityWebRequest.
Anyone ?