For some reason, the audio clip wont play. I even chacked it with Debug.log(audioSource.clip.LoadState);
and it returned
Loaded
. I dont know what goes wrong and prevents the source from playing the clip. Also, the clip name is blank.
The code :
IEnumerator LoadMusic(string path, AudioSource audioSource)
{
if (File.Exists(path))
{
using (UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV))
{
yield return uwr.SendWebRequest();
var uwrClip = DownloadHandlerAudioClip.GetContent(uwr);
audioSource.clip = uwrClip;
}
}
}
private void LoadAssets()
{
if (charts.Length == 0)
{
return;
}
else if (startingValue != currentDropdownValue)
{
startingValue = currentDropdownValue;
string musicToLoad = currentFilePath;
StartCoroutine(LoadMusic(musicToLoad, SelectorAudioPreview));
SelectorAudioPreview.Play();
}
}
(I know that i could've used charts.Lenght != 0, but I was too tired to think straight back then.)
CodePudding user response:
Add audioSource.Play();
after audioSource.clip = uwrClip;
‘
And remember to check if in your scene there is a audio listener. Check also that the audioSource settings are ok to listen, like the volume, mute, distance...