Function to load audio in LoadFile.cs:
public async Task<AudioClip> LoadAudioFile(string path) // Loads *.mp3's
{
//Load audio from the chosen *.mp3 file
using UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.MPEG);
var operation = www.SendWebRequest();
while (!operation.isDone)
await Task.Yield();
if (www.result == UnityWebRequest.Result.Success)
return DownloadHandlerAudioClip.GetContent(www);
else
return null;
}
Calling the function in TrackLoader.cs:
beatmap.music = await LoadFile.instance.LoadAudioFile(Path.Combine(folderPath, beatmap.musicName));
Users are able to create their own custom levels in the rhythm game I'm developing, meaning they can import their own audio, art for the song, etc. I load audio with the above method (and essentially the same way with images).
Loading a 4 minute *.mp3 takes around 300-450ms on my good computer when I run this. In the game, loading the songs when I enter the song select scene can take up minutes which is far too long. I'm not sure how to implement a better solution.
Games such as osu!mania and Quaver have instant access to the music, and the best guess I have is the music is being streamed instead of loaded all at once then played.
I attempted to Google how to do this but I'm stumped. How can I speed up this process?
If there is anything I missed I will be happy to provide anything at all.
Reason for needing this: To be able to preview songs in song select.
VIDEO SHOWING HOW SLOW LOADING CURRENTLY IS
I understand there may be design flaws with this such as not background loading before switching to the song select scene, loading what is clicked, etc. However, even with those implemented I believe it won't achieve the quickness I need such as how Quaver has it. I don't know why the FPS is so low and why the debugger keeps going even after exiting play mode.