I am developing a game however I am stuck on a problem and am not sure how to go about this.
I have links to directories that contain a .wav, .mp3, and .ogg files however I don’t know how I am meant to play them?
Any help will be appreciated!
I am developing a game however I am stuck on a problem and am not sure how to go about this.
I have links to directories that contain a .wav, .mp3, and .ogg files however I don’t know how I am meant to play them?
Any help will be appreciated!
You can load a file from its path with a web request, here’s some code from a test I use:
private IEnumerator LoadFromWebRequest()
{
string filePath = Path.Combine(Application.streamingAssetsPath, audioClipFileName);
#if UNITY_WEBGL && !UNITY_EDITOR
filePath = System.Uri.EscapeUriString(filePath);
#endif
webRequest = UnityWebRequestMultimedia.GetAudioClip(filePath, audioType);
yield return webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.Success)
{
audioClip = DownloadHandlerAudioClip.GetContent(webRequest);
Log("AudioClip loaded");
}
else
{
Log($"Error loading AudioClip: {webRequest.error}.");
}
}
This function is started as a Coroutine to load a file from the streaming asset folder, but you could set any valid file path there. Be sure to properly set the audioType
value in the UnityWebRequestMultimedia.GetAudioClip
call!
Cheers!