예제 #1
0
        private IEnumerator LoadAndPlayDelay(string uid, string path, GameObject target, bool loop, bool isSound, AudioType format)
        {
            isLoading = true;
            ZLog.Log("audio manager try load data that path = " + path);
            using (var loader = UnityWebRequestMultimedia.GetAudioClip("file://" + path, format))
            {
                yield return(loader.SendWebRequest());

                isLoading = false;
                if (loader.isNetworkError)
                {
                    ZLog.Warning("load the aidio error that msg = " + loader.error);
                    NotifyManager.SendNotify(NotifyType.OnAudioLoadError, path);
                    yield break;
                }
                AudioClip clip = null;
                if ((Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) && format == AudioType.MPEG)
                {
                    clip = AudioUtil.FromMp3Data(loader.downloadHandler.data);
                }
                else
                {
                    clip = DownloadHandlerAudioClip.GetContent(loader);
                }
                if (clip.length < 1)
                {
                    ZLog.Warning("load the audio is empty that path = " + path);
                    NotifyManager.SendNotify(NotifyType.OnAudioLoadError, path);
                    yield break;
                }
                AudioInfo info = new AudioInfo
                {
                    uid  = uid,
                    clip = clip
                };
                clips.Add(info);
                if (isSound)
                {
                    PlaySound(clip, target);
                }
                else
                {
                    ActiveMusic(clip, target, loop);
                }
                NotifyManager.SendNotify(NotifyType.OnAudioPlay, path);
            }

            loadCoroutine = null;
        }