38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.Networking;
|
|||
|
|
|
|||
|
|
public class AudioLoader
|
|||
|
|
{
|
|||
|
|
public static IEnumerator LoadAudio(string auFullName, AudioLoadedEventHandler handler, AudioSource asHandler, AudioType auType = AudioType.MPEG)
|
|||
|
|
{
|
|||
|
|
// Debug.Log(auFullName);
|
|||
|
|
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(auFullName, auType))
|
|||
|
|
{
|
|||
|
|
yield return www.SendWebRequest();
|
|||
|
|
|
|||
|
|
if (www.result == UnityWebRequest.Result.Success)
|
|||
|
|
{
|
|||
|
|
AudioClip auClip = DownloadHandlerAudioClip.GetContent(www);
|
|||
|
|
auClip.name = Path.GetFileNameWithoutExtension(auFullName);
|
|||
|
|
|
|||
|
|
if (handler != null)
|
|||
|
|
{
|
|||
|
|
handler(auClip, asHandler);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.Log(string.Format("Error loading remote audio<69><6F>{0}<7D><>:{1} ", auFullName, www.error));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>Ƶ<EFBFBD><C6B5><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD>¼<EFBFBD>ί<EFBFBD><CEAF>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="ac"><3E><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD></param>
|
|||
|
|
public delegate void AudioLoadedEventHandler(AudioClip auClip, AudioSource asHandler);
|