示例#1
0
        private static void OnCustomTrackLoaded(CustomMusicLoadSpec loadSpec, AudioClip clip)
        {
            string trackName = loadSpec.GetDisplayName();

            if (clip == null)
            {
                customMusic.Remove(trackName);
            }
            else
            {
                customMusic[trackName] = clip;
            }
        }
示例#2
0
        internal static IEnumerator LoadMusicTrack(CustomMusicLoadSpec loadSpec)
        {
            AudioClip audioClip = null;
            string    path      = loadSpec.GetAbsolutePath();

            if (!File.Exists(path))
            {
                Debug.LogError("Unable to load track at path: " + path + "! File does not exist.");
                loadSpec.callback?.Invoke(loadSpec, null);
                yield break;
            }

            UnityWebRequest webRequest = loadSpec.audioType == AudioType.MPEG
                                        ? UnityWebRequest.Get(path)
                                        : UnityWebRequestMultimedia.GetAudioClip(path, loadSpec.audioType);

            webRequest.SendWebRequest();
            while (!webRequest.isDone)
            {
                yield return(new WaitForSecondsRealtime(0.05f));
            }

            if (webRequest.isNetworkError || webRequest.isHttpError)
            {
                Debug.LogError("Failed to load musicTrack at: " + path);
            }
            else
            {
                audioClip = loadSpec.audioType == AudioType.MPEG
                                                ? Mp3ToWavClip(Path.GetFileName(path) + ".wav", webRequest.downloadHandler.data)
                                                : DownloadHandlerAudioClip.GetContent(webRequest);

                webRequest.Dispose();
            }

            loadSpec.callback?.Invoke(loadSpec, audioClip);
        }